Someone tell me why I get this message "unexpected $end" at the last line of code, please <?php mysql_connect(localhost,root,""); mysql_select_db(test) or die( "Unable to select database"); if(!empty($_POST["submit"])) { $apt = $_POST['apt']; $query="SELECT * FROM payments Where apt='$apt'"; $result=mysql_query($query); if(mysql_num_rows($result)) ?> <html><head><script type="text/javascript"> if ($late = "L") {$rentdue = $rentdue + 10;} var excess = $amtpaid - $rentdue; var totOwed = $rentdue + $prevbal + $secdep + $damage + $latechg + $courtcost + $nsf - $hudpay; if ($amtpaid >= totOwed) { $prevbal = totOwed - $amtpaid; excess = 0 ; $secdep = 0 ; $damage = 0 ; $latechg = 0 ; $courtcost = 0 ; $nsf = 0; } if (excess < $prevbal && $amtpaid > $rentdue) { $prevbal = $prevbal - excess; excess = 0} if (excess >= $prevbal) { excess = excess - $prevbal; $prevbal = 0 ; } if (excess < $secdep && $amtpaid > $rentdue) { $secdep = $secdep - excess; excess = 0} if (excess >= $secdep) { excess = excess - $secdep; $secdep = 0 ; } if (excess < $damage && $amtpaid > $rentdue) { $damage = $damage - excess; excess = 0} if (excess >= $damage) { excess = excess - $damage; $damage = 0 ; } if (excess < $latechg && $amtpaid > $rentdue) { $latechg = $latechg - excess; excess = 0} if (excess >= $latechg) { excess = excess - $latechg; $latechg = 0 ; } if (excess < $courtcost && $amtpaid > $rentdue) { $courtcost = $courtcost - excess; excess = 0} if (excess >= $courtcost) { excess = excess - $courtcost; $courtcost = 0 ; } if (excess < $nsf && $amtpaid > $rentdue) { $nsf = $nsf - excess; excess = 0} if (excess >= $nsf) { excess = excess - $nsf; $nsf = 0 ; } } </script> <?php> $sql = "UPDATE payments SET amtpaid = '0', prevbal, tentpay = '0', datepaid = ' ', late = ' ', damage, courtcost, nsf, latechg, secdep, comments = ' ', paidsum = '0' WHERE prevbal + rentdue = amtpaid OR late = 'L'); mysql_query($sql) or die("Update query failed."); echo "Records have been updated"; ?> </head></html> Code (markup):
You need to add a double quote at the end of your $sql. $sql = "UPDATE payments SET amtpaid = '0', prevbal, tentpay = '0', datepaid = ' ', late = ' ', damage, courtcost, nsf, latechg, secdep, comments = ' ', paidsum = '0' WHERE prevbal + rentdue = amtpaid OR late = 'L')";
Are you getting your die message "Update query failed", or just no update? Either way, try changing this to output and debug. change: mysql_query($sql) or die("Update query failed."); to: echo $qry; // so you can see if the data you expect to be update is being updated. mysql_query($sql); if ($err = mysql_error()) echo $err; // show query error If everything looks ok, my next step would be to go to phpmyadmin and run a query with the criteria you are trying to match on to see if any rows are found. Something like select * from payments WHERE prevbal + rentdue = amtpaid OR late = 'L' The data may not have any matching rows.
I checked the database and I do have have the rows. I changed the code as you suggested but the result is still nada. Someone said I was mixing variables and that was the cause?
amtpaid = '0', prevbal, tentpay = '0', datepaid = ' ', late = ' ', damage, courtcost, nsf, latechg, secdep, comments = ' ', paidsum = '0' WHERE prevbal + rentdue = amtpaid OR late = 'L';
I got that much : ) I was more looking for a verbal explanation than see a query. With the query as is, I dont see any conditions to be met based on variables. All fields will be reset to empty/0 on all records where prevbal + rentdue = amtpaid OR late = 'L' It is looking at the database field amtpaid, not a variable value amtpaid.
I'm sorry, I'm really a novice here. I want to clear the fields in the database record depending on the value of the amtpaid field in the database record. I'm sure you're right but I don't know how to assign values in the javascript to the php? There's nothing in my references this advanced.