简体   繁体   中英

Mysql syntax error issue

I've got a message while i'm run following sql query...

"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 'group = 'dfdfd' WHERE id = '39'' at line 1"

Sql query:

$sql_update = mysql_query("UPDATE addcontacts SET surename = '$surname_g', group = 
'$g_g' WHERE id = '$id'");

Please use ` to enclose group, it is being treated as special ( group by keyword of SQL) by mysql

Use the following:

 UPDATE addcontacts SET surename = '$surname_g', `group` = '$g_g' WHERE id = '$id'

Note `group` and not group

尝试:

$sql_update = mysql_query("UPDATE addcontacts SET surename = '".$surname_g."', `group` = '".$g_g."' WHERE id = '".$id."'");

Your id might be an integer and you are enclosing it with two single quotes (') and that would really produce the error.

$sql_update = mysql_query("UPDATE addcontacts SET surename = '{$surname_g}', group = 
'{$g_g}' WHERE id = {$id}");

Thank you :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM