I get the following message: with this code. What does it mean? <?php $apt=$_POST['search_term']; $stat = mysql_connect("localhost","root",""); $stat = mysql_select_db("prerentdb"); $query = "SELECT name FROM payments WHERE late = 'L'"; $stat = @mysql_fetch_assoc(mysql_query($query)); echo $stat["name"]; $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')"; $stat = mysql_query($query) or die('Query failed: ' . mysql_error()); mysql_close(); echo "data inserted<br /><br />"; ?> Code (markup):
I hope we get the issues resolved. I don't have a lot of time but I'm trying to learn. I've been told a couple of times how terrible my coding is but that is why I ask questions. Good luck and don't be discouraged by the bad eggs.
That's because `late` field (column) does not exists in DB look into DB table `payhist` and you will see there is no `late` field
I changed the code per suggestons from another forum but can't get it to work. I sure need to get this to work. Below is the new code: <?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(); // echo $query for debugging purposes echo "query: $query<br />"; ?> PHP: This is the result:
You're newbie right? just after connecting to mysql, you are calling mysql_query($query), but $query does not exists. You also can't call 2 queries in one mysql_query(); & you didn't enter VALUES that should be inserted It should be like 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) VALUES ('1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1')"; $query2 =" Select * From payments WHERE paidsum= 'rentdue' OR late = 'L'"; mysql_query($query); mysql_query($query2) or die('Query failed: ' . mysql_error() . " - query: $query"); echo "data inserted</font><br /><br />"; mysql_close(); // echo $query for debugging purposes echo "query: $query<br />"; ?> PHP: that VALUES ('1', '1', '1', '1', '1', '1', '1', '1', '1', '1', '1') PHP: is just to fill what has to be filled in correct syntax
I used your below code and got the message below. it entered the integer fields but not the name, apt, datepaid, comments <?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) VALUES ('$name', '$apt', '$amtpaid', '$rentdue', '$prevbal', '$hudpay', '$tentpay', '$datepaid', '$late', '$comments', '$paidsum')"; $query2 ="Select *From payments WHERE late = 'L'"; mysql_query($query); mysql_query($query2) or die('Query failed: ' . mysql_error() . " - query: $query"); echo "data inserted</font><br /><br />"; mysql_close(); // echo $query for debugging purposes echo "query: $query<br />"; ?> data inserted query: INSERT INTO payhist (name,apt,amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,comments,paidsum) VALUES ('', '', '', '', '', '', '', '', '', '')
I used your below code and got the message below. it entered the integer fields but not the name, apt, datepaid, comments <?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) VALUES ('$name', '$apt', '$amtpaid', '$rentdue', '$prevbal', '$hudpay', '$tentpay', '$datepaid', '$late', '$comments', '$paidsum')"; $query2 ="Select *From payments WHERE late = 'L'"; mysql_query($query); mysql_query($query2) or die('Query failed: ' . mysql_error() . " - query: $query"); echo "data inserted</font><br /><br />"; mysql_close(); // echo $query for debugging purposes echo "query: $query<br />"; ?> PHP: data inserted
you mean like this? <?php mysql_connect(localhost,root,""); mysql_select_db(prerentdb) or die( "Unable to select database"); $name = $_POST['name']; $apt = $_POST['apt']; $amtpaid = $_POST['amtpaid']; $rentdue = $_POST['rentdue']; $prevbal = $_POST['prevbal']; $hudpay = $_POST['hudpay']; $tentpay = $_POST['tentpay']; $datepaid = $_POST['datepaid']; $comments = $_POST['comments']; $paidsum = $_POST['paidsum']; $query = "INSERT INTO payhist (name,apt,amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,comments,paidsum) VALUES ('$name', '$apt', '$amtpaid', '$rentdue', '$prevbal', '$hudpay', '$tentpay', '$datepaid', '$comments', '$paidsum')"; $query2 ="Select * From payments WHERE late = 'L'"; mysql_query($query); mysql_query($query2) or die('Query failed: ' . mysql_error() . " - query: $query"); echo "data inserted</font><br /><br />"; mysql_close(); // echo $query for debugging purposes echo "query: $query<br />"; ?>
Do you mean like this? <?php mysql_connect(localhost,root,""); mysql_select_db(prerentdb) or die( "Unable to select database"); $name = $_POST['name']; $apt = $_POST['apt']; $amtpaid = $_POST['amtpaid']; $rentdue = $_POST['rentdue']; $prevbal = $_POST['prevbal']; $hudpay = $_POST['hudpay']; $tentpay = $_POST['tentpay']; $datepaid = $_POST['datepaid']; $comments = $_POST['comments']; $paidsum = $_POST['paidsum']; $query = "INSERT INTO payhist (name,apt,amtpaid,rentdue,prevbal,hudpay,tentpay,datepaid,comments,paidsum) VALUES ('$name', '$apt', '$amtpaid', '$rentdue', '$prevbal', '$hudpay', '$tentpay', '$datepaid', '$comments', '$paidsum')"; $query2 ="Select * From payments WHERE late = 'L'"; mysql_query($query); mysql_query($query2) or die('Query failed: ' . mysql_error() . " - query: $query"); echo "data inserted</font><br /><br />"; mysql_close(); // echo $query for debugging purposes echo "query: $query<br />"; ?> PHP:
this is more safe $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']); $comments = mysql_real_escape_string($_POST['comments']); $paidsum = mysql_real_escape_string($_POST['paidsum']); PHP:
I had mistake in my code, replace these lines with $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']); $comments = mysql_real_escape_string($_POST['comments']); $paidsum = mysql_real_escape_string($_POST['paidsum']); PHP: you have something like $comments = $mysql_real_escape_string(_POST['comments']); hehe