This below is my latest attempt and below that the errors encountered. A copy of the database is at the bottom: there is no form
<?php
error_reporting(E_ALL);
// this code should update the database and gives a confirmation
$ud_id=$_POST['ud_id'];
$ud_amtpaid=$_POST['ud_amtpaid'];
$ud_rentdue=$_POST['ud_rentdue'];
$ud_prevbal=$_POST['ud_prevbal'];
$ud_misc=$_POST['ud_misc'];
$ud_tentpay=$_POST['ud_tentpay'];
$ud_hudpay=$_POST['ud_hudpay'];
$ud_datepaid=$_POST['ud_datepaid'];
if(($ud_misc + $ud_prevbal + $ud_rentdue) == $ud_amtpaid)
{
$misc = 0;
$prevbal = 0;
$amtpaid = 0;
$tentpay = 0;
$datepaid = " ";
}
if (!$conn = @mysql_connect(localhost,root,"")) {
echo 'could not connect to MYSQL: ' .mysql_error();
exit;
}
if(!@mysql_select_db('test')) {
echo 'Unable to select database: ' .mysql_error();
exit;
}
// mysql_query returns false on failure
$sql = "SELECT FROM testtable";
$result = @mysql_query($sql);
if(!$result) {
echo "could not run query (sql); " .mysql_error();
exit;
}
// if we expect rows, let's make sure some exist
if(mysql_num_rows($result) < 1) {
echo "no rowsmatch your query, Please try again";
exit;
}
// We know $result is valid and rows exist to fetch
while ($row = mysql_fetch_assoc($result)) {
print_r($row);
}
$query = sprintf(
"UPDATE testtable
SET
amtpaid='%s',
prevbal='%s',
misc='%s',
tentpay='%s',
hudpay='%s',
datepaid='%s'
WHERE id=%d",
mysql_real_escape_string($ud_amtpaid),
mysql_real_escape_string($ud_prevbal),
mysql_real_escape_string($ud_misc),
mysql_real_escape_string($ud_tentpay),
mysql_real_escape_string($ud_hudpay),
mysql_real_escape_string($ud_datepaid),
(int) $ud_id
);
// $result = mysql_query($query) or die(mysql_error()."<br />\n$query");
// $query="UPDATE testtable SET id=".$ud_id.", amtpaid=".$ud_amtpaid.", prevbal=".$ud_prevbal.", // misc=".$ud_misc.", tentpay=".$ud_tentpay.", hudpay=".$ud_hudpay.", datepaid='".$ud_datepaid."' // WHERE id=".$ud_id.";
// echo $query."\n<br>";
// on numeric values you can delete the single quotes.
mysql_query($query);
echo "Records Updated";
mysql_close();
?>
Notice: Undefined index: ud_id in C:\xampp\htdocs\hofiles\refreshprerent.php on line 4
Notice: Undefined index: ud_amtpaid in C:\xampp\htdocs\hofiles\refreshprerent.php on line 5
Notice: Undefined index: ud_rentdue in C:\xampp\htdocs\hofiles\refreshprerent.php on line 6
Notice: Undefined index: ud_prevbal in C:\xampp\htdocs\hofiles\refreshprerent.php on line 7
Notice: Undefined index: ud_misc in C:\xampp\htdocs\hofiles\refreshprerent.php on line 8
Notice: Undefined index: ud_tentpay in C:\xampp\htdocs\hofiles\refreshprerent.php on line 9
Notice: Undefined index: ud_hudpay in C:\xampp\htdocs\hofiles\refreshprerent.php on line 10
Notice: Undefined index: ud_datepaid in C:\xampp\htdocs\hofiles\refreshprerent.php on line 11
could not run query (sql); You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'FROM testtable' at line 1
apt dep name amtpaid rentdue prevbal misc tentpay hudpay datepaid
A1 name1 530 530 0 0 530 0 8/5/2010
A2 name2 150 500 350 0 150 0 8/4/2010
A3 name3 437 555 0 -118 437 0 8/2/2010
A4 name4 505 530 -25 0 505 0 8/1/2010
B1 name5 490 490 10 0 490 0 8/3/2010