Hi, I'm trying to refresh all records with values in the "amtpaid" field. Someone advise why the error? ========================================================================== the code: <html> <head> <title>Refresh payment database file</title> </head> <body> <?php /* Attempt MySQL server connection. Assuming you are running MySQL server with default setting (user 'root' with no password) */ $link = mysqli_connect("localhost", "root", "", "homedb"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } //MySqli Select Query $sql = "select * FROM paytbl where amtpaid |=0"; $result = mysqli_query($link,$sql); if (!$result) { printf("Error: %s\n", mysqli_error($link)); exit(); }else{ $results = array(); while($row = mysqli_fetch_array($result)){ $results[] = $row; } // ---------------------------------------- $due = $amtdue + $prevbal + $latechg + $secdep + $damage + $courtcost + $nsf - $hudpay; /* if no pay or part pay, add $35 to latechg field and amount not paid to prevbal field */ if ($amtpaid < $due) { $prevbal = $amtdue - $amtpaid; $latechg = $latechg + 35.00; } /* if over-payment subtract over-payment from prevbal */ if ($amtpaid > $due) { $prevbal = $amtpaid - $amtdue; } // give every effected record the below values $amtpaid = 0; $paidday = ''; $secdep = 0; $damage = 0; $courtcost = 0; $nsf = 0; $hudpay = 0; $comments = ' '; // Perform a query, check for error $sql = "UPDATE paytbl SET amtpaid = '$amtpaid', prevbal = '$prevbal', latechg = '$latechg', secdep = '$secdep', damage = '$damage', courtcost = '$courtcost', nsf = '$nsf', hudpay = '$hudpay', comments = '$comments' WHERE id=$id"; if(mysqli_query($link, $sql)){ echo "record was updated successfully."; } else { echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // Close connection mysqli_close($link); } ?> </body></html> PHP: --------------------------------------- the result: Error: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '=0' at line 1
Your error is on line 16 but I think you'll run into problems further down too. But let's start at the top. $sql = "select * FROM `paytbl` where `amtpaid` !=0"; I've added `ticks` to the table and column names but your big gotcha is that you had a pipe | instead of an exclamation ! Change that and you'll make some progress.