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.
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 ('', '', '', '', '', '', '', '', '', '')
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
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(); ?>
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
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
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