简体   繁体   English

错误尝试使用PHP插入MySQL表时

[英]ERROR When trying to insert into MySQL table with PHP

I don't know what's wrong with my syntax, but I'm missing something: 我不知道我的语法有什么问题,但是我缺少一些东西:

$createrequest = mysql_query("INSERT INTO products_updates_queue (id, kid,
product_version_id, key, ip) VALUES ('$request_id', '$uid', '$version_id',
'$request_key', '$request_ip')");

I receive this 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 'key, ip) VALUES ('j4ctveyd0x62', '1', 'z451ah3', 'hqbyu7bhg8za', '64.134.163.2' at line 2" “您的SQL语法有错误;请查看与您的MySQL服务器版本相对应的手册,以找到在'key,ip'附近使用正确的语法VALUES('j4ctveyd0x62','1','z451ah3','hqbyu7bhg8za'第64行的“ 64.134.163.2”

Can anyone see what I am missing? 谁能看到我所缺少的吗?

I think key is a reserved word, and you should avoid using it as a column name. 我认为key是保留字,您应该避免将其用作列名。 Try using backticks around it: 尝试在其周围使用反引号:

$createrequest = mysql_query("INSERT INTO products_updates_queue (id, uid, product_version_id, `key`, ip) VALUES ('$request_id', '$uid', '$version_id', '$request_key', '$request_ip')");

key is a reserved word in MySQL. key是MySQL中的保留字 Avoid it, or wrap it in backticks. 避免使用它,或将其包装在反引号中。

Edit: And I hope you escaped the variables you're putting into that query. 编辑:我希望您转义了要放入该查询的变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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