the error message is telling you that the table mentioned in the query does not have a column called late
by the way, you don’t have to pull data out of a table using php if all you want to do is turn around and insert that data into another table – you can do it all with a single INSERT SELECT statement
edit: scratch that, i think you’re getting the values from a form (i don’t actually do php)
so which of the two queries is generating the error? and why are you extracting the name in the first query?
Below is my code and below that, the payments table with the late(L). An insertion is made into the payhist table but without name, apt, datepaid late, comments or paidsum, only zeros for the other fields. I get the echo
“data inserted”
?
<?php
mysql_connect(localhost,root,"");
mysql_select_db(prerentdb) or die( "Unable to select database");
$query="SELECT * FROM payments Where late='L'";
$result=mysql_query($query);
$num=mysql_numrows($result);
$name=$_POST['name'];
$apt=$_POST['apt'];
$amtpaid=$_POST['amtpaid'];
$rentdue=$_POST['rentdue'];
$prevbal=$_POST['prevbal'];
$hudpay=$_POST['hudpay'];
$tentpay=$_POST['tentpay'];
$datepaid=$_POST['datepaid'];
$late=$_POST['late'];
$comments=$_POST['comments'];
$paidsum=$_POST['paidsum'];
$query = "
INSERT INTO payhist (name,apt,amtpaid,rentdue,prevbal,
hudpay,tentpay,datepaid,late,comments,paidsum)
VALUES('$name','$apt','$amtpaid','$rentdue','$prevbal',
'$hudpay','$tentpay','$datepaid','$late','$comments','$paidsum')";
echo "data inserted</font><br /><br />";
$stat = mysql_query($query) or die('Query failed: ' . mysql_error());
mysql_close();
?>
Payment Report… for January / 2011
Apt Rent Prev Late Sec . Court . Tenant Hud Date .
Tenant # Paid Due Bal Chg Dep Dmg Cost NSF Pay Paid L Comment
Do a print_r($_POST); to check the values sent to the script.
And pass them through mysql_real_escape_string() before using them in the query to prevent sql injection.
Also for debugging purposes instead of echoing ‘data inserted’ BEFORE you execute the insert query, you might want to echo that after, and echo the value of $query as well.
But you aren’t inserting in the payments table, you’re inserting in the payhist table. And you’re inserting with all empty values. Because the values you’re getting from the $_POST super global don’t exist. $_POST is empty.
Where exactly are you getting the to be inserted values from?
It may be a copy & paste error, but as you can see from the colours in the code you posted, you’re missing the closing quotes (") at the end of the query.