php/SQL syntax error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
dreeves
Forum Commoner
Posts: 39
Joined: Thu Oct 22, 2009 8:53 am

php/SQL syntax error

Post by dreeves »

I'm getting an error when my code is ran. The error is:
failed - 1064: 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 'on WHERE dam=3546' at line 1

$om_agreement is a checkbox, so the "on" mentioned above means that the box was checked.
If $om_agreement for a dam is checked, then the corresponding dam will be checked in the dam_list table.

Code: Select all

FOREACH($_POST['om_agreement'] as $row=>$om_agreement)
{
$om_agreement=mysql_real_escape_string($om_agreement);
$dam=mysql_real_escape_string($_POST['dam'][$row]);
 
$query2="UPDATE dam_list SET om_agreement = $om_agreement WHERE dam=$dam";
 
if (!mysql_query($query2, $link))
    {
    die("failed - " . mysql_errno() . ": " .
    mysql_error());
    }
        echo "$line O&M updated";
    }
I think the message is saying that there is an error in my query, but I don't see it. I could use a fresh set of eyes on this. Thanks.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: php/SQL syntax error

Post by AbraCadaver »

I don't know what the data types are of om_agreement and dam, but if they aren't numeric you need to quote them:

Code: Select all

$query2="UPDATE dam_list SET om_agreement = [color=#FF0000]'[/color]$om_agreement[color=#FF0000]'[/color] WHERE dam = [color=#FF0000]'[/color]$dam[color=#FF0000]'[/color]";
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply