这个SQL语句的问题

jas*_*ite 1 mysql sql

   $query="INSERT INTO `main_table` (`count`) VALUES ('$count') WHERE userid='$someid'";
Run Code Online (Sandbox Code Playgroud)

基本上我喜欢在main_table中将count的新值插入到变量count中,其中userid等于变量some​​id.

SQL抱怨此语句的语法.

Mar*_*ers 5

要更新现有行,应使用UPDATE语句而不是INSERT语句.

UPDATE `main_table`
SET `count` = '$count'
WHERE userid='$someid'
Run Code Online (Sandbox Code Playgroud)

看到它在线工作:sqlfiddle

INSERT仅用于在表中插入全新行.在INSERT语句中使用WHERE子句是不合法的.