SQL查询错误 - 检查与MySQL服务器版本对应的手册

时间:2021-01-05 07:01:25

SQL - It's been a while.

SQL - 已经有一段时间了。

I need to figure out why the following SQL is failing:

我需要弄清楚以下SQL失败的原因:

$query = "INSERT INTO users ('c_id', 'c_email', 'c_fname', 'csname', 'c_mobile', 'c_add_1', 'c_add_2', 'c_city', 'c_county', 'c_postcode', 'c_comments') VALUES ('null','josh','hh', 'hh', 'hhhh', 'hh', 'hhh', 'hhh', 'hhhh', 'hh', 'hhh')";

I have tried it without the c_id being null.

我试过没有c_id为null。

I am getting the following message:

我收到以下消息:

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 ''c_id', 'c_email', 'c_fname', 'csname', 'c_mobile', 'c_add_1', 'c_add_2', 'c_cit' at line 1 

Here is my code where the query is executed:

这是执行查询的代码:

if (mysqli_query($conn,$query))
{
   echo "k";
}       
else
{
    echo mysqli_error($conn);
}

1 个解决方案

#1


In SQL, single quotes (') denote string literals, not object names. You should drop them from your column list:

在SQL中,单引号(')表示字符串文字,而不是对象名称。您应该从列列表中删除它们:

$query = "INSERT INTO users (c_id, c_email, c_fname, csname, c_mobile, c_add_1, c_add_2, c_city, c_county, c_postcode, c_comments) VALUES ('null','josh','hh', 'hh', 'hhhh', 'hh', 'hhh', 'hhh', 'hhhh', 'hh', 'hhh')";

#1


In SQL, single quotes (') denote string literals, not object names. You should drop them from your column list:

在SQL中,单引号(')表示字符串文字,而不是对象名称。您应该从列列表中删除它们:

$query = "INSERT INTO users (c_id, c_email, c_fname, csname, c_mobile, c_add_1, c_add_2, c_city, c_county, c_postcode, c_comments) VALUES ('null','josh','hh', 'hh', 'hhhh', 'hh', 'hhh', 'hhh', 'hhhh', 'hh', 'hhh')";