Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/55.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php MySQL更新语法_Php_Mysql_Mysqli - Fatal编程技术网

Php MySQL更新语法

Php MySQL更新语法,php,mysql,mysqli,Php,Mysql,Mysqli,我正试图在PHP脚本中编写一个MySQL,它将更新数据库中的一个字段,但是我得到了错误: Fatal error: Wrong SQL: Error: 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 ''user' SET 'currentsong' = '' WHERE 'us

我正试图在PHP脚本中编写一个MySQL,它将更新数据库中的一个字段,但是我得到了错误:

Fatal error: Wrong SQL: Error: 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 ''user' SET 'currentsong' = '' WHERE 'userid' = '1893'' 
在使用此代码时

$setcurrentsongsql = "UPDATE 'user' SET 'currentsong' = '$currentsong' WHERE 'userid' = '$sql1'";
$setcurrentsong = $db->query($setcurrentsongsql);
我相信这很简单,但我完全困惑不解。即使我用一个普通字符串替换变量,它也不起作用


提前感谢您的帮助。

对表名和列名使用反勾号而不是单引号。请尝试以下操作:

$setcurrentsongsql = "UPDATE `user` SET `currentsong` = '$currentsong' WHERE `userid` = '$sql1'";
在MySQL中,标识符引号字符是回勾“`”。这个简短的页面应该能让您很好地理解模式规则、标识符等:

mySQL使用backtick`表示列和表名,而撇号表示字符串常量。但是,除非您使用的是(例如,您的表实际上被称为“表”),或者您的表或列名包含空格(例如“我的表”),否则不需要这些

您可以使用:

$setcurrentsongsql = "UPDATE `user` SET `currentsong` = '$currentsong' WHERE `userid` = '$sql1'";
或:


此外,如果
$currentsong
来自不受信任的来源,您可能需要担心。

删除用户、currentsong等周围的
'
,然后再次测试。这个答案本身并不重要,或者已经在注释中给出了答案。如果你提到为什么op应该使用撇号后面的勾号,你会从我这里得到+1。
$setcurrentsongsql = "UPDATE user SET currentsong = '$currentsong' WHERE userid = '$sql1'";