1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

trying to insert

Discussion in 'PHP' started by ckdoublenecks, Jan 21, 2011.

  1. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #21
    Based on your first code, please show us the database structure for the table payments

    As stated above, the error is saying in that table there is no row called Late, perhaps you are querying the wrong table, so with that in mind then show us your complete database structure, if your unfamiliar with this, you will find your database structure on your phpmyadmin panel, click Export and post the data here.
     
    MyVodaFone, Jan 23, 2011 IP
  2. ckdoublenecks

    ckdoublenecks Guest

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #22
    Notice: Use of undefined constant localhost - assumed 'localhost' in C:\xampp\htdocs\hofiles\lateinsert.php on line 3

    Notice: Use of undefined constant root - assumed 'root' in C:\xampp\htdocs\hofiles\lateinsert.php on line 3

    Notice: Use of undefined constant prerentdb - assumed 'prerentdb' in C:\xampp\htdocs\hofiles\lateinsert.php on line 4

    Notice: Undefined index: name in C:\xampp\htdocs\hofiles\lateinsert.php on line 5

    Notice: Undefined index: apt in C:\xampp\htdocs\hofiles\lateinsert.php on line 6

    Notice: Undefined index: amtpaid in C:\xampp\htdocs\hofiles\lateinsert.php on line 7

    Notice: Undefined index: rentdue in C:\xampp\htdocs\hofiles\lateinsert.php on line 8

    Notice: Undefined index: prevbal in C:\xampp\htdocs\hofiles\lateinsert.php on line 9

    Notice: Undefined index: hudpay in C:\xampp\htdocs\hofiles\lateinsert.php on line 10

    Notice: Undefined index: tentpay in C:\xampp\htdocs\hofiles\lateinsert.php on line 11

    Notice: Undefined index: datepaid in C:\xampp\htdocs\hofiles\lateinsert.php on line 12

    Notice: Undefined index: comments in C:\xampp\htdocs\hofiles\lateinsert.php on line 13

    Notice: Undefined index: paidsum in C:\xampp\htdocs\hofiles\lateinsert.php on line 14

    Notice: Undefined index: name in C:\xampp\htdocs\hofiles\lateinsert.php on line 15

    Notice: Undefined index: apt in C:\xampp\htdocs\hofiles\lateinsert.php on line 15

    Notice: Undefined index: amtpaid in C:\xampp\htdocs\hofiles\lateinsert.php on line 16

    Notice: Undefined index: rentdue in C:\xampp\htdocs\hofiles\lateinsert.php on line 17

    Notice: Undefined index: prevbal in C:\xampp\htdocs\hofiles\lateinsert.php on line 18

    Notice: Undefined index: hudpay in C:\xampp\htdocs\hofiles\lateinsert.php on line 19

    Notice: Undefined index: tentpay in C:\xampp\htdocs\hofiles\lateinsert.php on line 20

    Notice: Undefined index: datepaid in C:\xampp\htdocs\hofiles\lateinsert.php on line 21

    Notice: Undefined index: comments in C:\xampp\htdocs\hofiles\lateinsert.php on line 22
    I showed the printout of the payments table in earlier postshowing the L in the fourth record.below is the latest results.
    ===============================================================
    Notice: Undefined index: paidsum in C:\xampp\htdocs\hofiles\lateinsert.php on line 23
    data inserted

    query: INSERT INTO payhist (name,apt,amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,comments,paidsum) VALUES ('', '', '', '', '', '', '', '', '', '')
     
    ckdoublenecks, Jan 23, 2011 IP
  3. ckdoublenecks

    ckdoublenecks Guest

    Messages:
    28
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #23
    it works with the below code but with the below message every time

    <?php
    mysql_connect(localhost,root,"");
    mysql_select_db(prerentdb) or die( "Unable to select database");
    $result=mysql_query($query); $num=mysql_numrows($result);

    $query = "INSERT INTO payhist (name,apt,amtpaid,rentdue,prevbal,
    hudpay,tentpay,datepaid,late,comments,paidsum)

    Select name,apt,
    amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,late,comments,
    paidsum From payments WHERE paidsum < rentdue OR late = 'L'";

    $stat = mysql_query($query) or die('Query failed: ' . mysql_error() . " - query: $query");
    echo "data inserted</font><br /><br />";
    mysql_close();

    ?>
    Warning: mysql_numrows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\hofiles\lateinsert.php on line 4
    data inserted
     
    ckdoublenecks, Jan 23, 2011 IP
  4. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #24
    I told you you can't call mysql before defining $query


    delete that, and try it. This



    <?php
    mysql_connect(localhost,root,"");
    mysql_select_db(prerentdb) or die( "Unable to select database");
    $query = "INSERT INTO payhist (name,apt,amtpaid,rentdue,prevbal,
    hudpay,tentpay,datepaid,late,comments,paidsum)";
    mysql_query($query);
    $query ="
    Select name,apt,
    amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,late,comments,
    paidsum From payments WHERE paidsum < rentdue OR late = 'L'";

    $stat = mysql_query($query) or die('Query failed: ' . mysql_error() . " - query: $query");
    echo "data inserted</font><br /><br />";
    mysql_close();

    ?>
     
    G3n3s!s, Jan 23, 2011 IP
  5. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #25
    Here, i have redone it. Also added on some code and security.

    
    
    <?php
    
        $apt = $_POST['search_term'];
        
        mysql_connect("localhost", "root", "") or die(mysql_error());
        mysql_select_db("prerentdb") or die(mysql_error());
        
        $query1 = mysql_query("SELECT `name` FROM `payments` WHERE `late` = 'L'") or die(mysql_error());
        if($query1){
            
            $fetch1 = mysql_fetch_assoc($query1);
            
                echo $fetch1['name'];
            
            $name         = mysql_real_escape_string($_POST['name']);
            $apt          = mysql_real_escape_string($_POST['apt']);
            $amtpaid      = mysql_real_escape_string($_POST['amtpaid']);
            $rentdue      = mysql_real_escape_string($_POST['rentdue']);
            $prevbal      = mysql_real_escape_string($_POST['prevbal']);
            $hudpay       = mysql_real_escape_string($_POST['hudpay']);
            $tentpay      = mysql_real_escape_string($_POST['tentpay']);
            $datepaid     = mysql_real_escape_string($_POST['datepaid']);
            $late         = mysql_real_escape_string($_POST['late']);
            $comments     = mysql_real_escape_string($_POST['comments']);
            $paidsum      = mysql_real_escape_string($_POST['paidsum']);
            
            $query2 = mysql_query("INSERT INTO `payhist` VALUES(name, apt, amtpaid, rentdue, prevbal, hudpay, tentpay, datepaid, late, comments, paidsum) VALUES('$name', '$apt', '$amtpaid', '$rentdue', '$prevbal', '$hudpay', '$tentpay', '$datepaid', '$late', '$comments', '$paidsum')") or die(mysql_error());
            if($query2){
                
                echo "The data has been inserted.";
                
            } else {
                echo "Error: query2";
                exit();
            }
            
        } else {
            echo "Error: query1";
            exit();
        }
        
        mysql_close();
    ?>
    
    
    PHP:
    I hoped i helped.

    Thanks,

    Michael
     
    CPAPubMichael, Jan 23, 2011 IP
  6. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #26
    I think he wants to INSERT and THEN SELECT.
    However' good code Michael
     
    G3n3s!s, Jan 24, 2011 IP
  7. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #27
    Ahh i see, well i am sure he or someone can adapt around the code what i have provided. Thank you for the nice comment.

    Thanks,

    Michael
     
    CPAPubMichael, Jan 24, 2011 IP
  8. G3n3s!s

    G3n3s!s Active Member

    Messages:
    325
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    80
    #28
    I think OP should try it for yourself, if he learns PHP ;)
     
    G3n3s!s, Jan 24, 2011 IP
  9. CPAPubMichael

    CPAPubMichael Peon

    Messages:
    231
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #29
    Indeed he should.

    Just read through it and try to understand what the functions do and how it works. Not sure of a function, then search it. http://www.php.net explains it very very well.

    Thanks,

    Michael
     
    CPAPubMichael, Jan 24, 2011 IP