简体   繁体   English

PHP/MySQL 插入查询

[英]PHP/MySQL Insert Query

For the life of me I can't get this insert query to work.对于我的生活,我无法让这个插入查询工作。

mysql_connect("**host**", "**username**", "**password**") or error("Could not connect: ".mysql_error());
mysql_select_db("**db_name**");
$db = mysql_query("INSERT INTO `pass_reset` (id,status,key,email) VALUES ('','0','$key','$email')");

It returns this error:它返回此错误:

You have an error in your SQL syntax;您的 SQL 语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key,email) VALUES ('','0','','')' at line 1检查与您的 MySQL 服务器版本相对应的手册,以获取在第 1 行的 'key,email) VALUES ('','0','','')' 附近使用的正确语法

Could someone help me with this?有人可以帮我解决这个问题吗? I'm literally pulling my hair out over this simple query.对于这个简单的查询,我简直是在抓狂。

Try the following:尝试以下操作:

$db = mysql_query("INSERT INTO `pass_reset` (id,status,`key`,email) VALUES ('','0','$key','$email')");

Because key is a reserved word by MySQL , you must escape it with the backticks ``因为keyMySQL 的保留字,所以你必须用反引号转义它 ``

KEY is a reserved word in MySQL, so you'd have to escape it with back ticks. KEY是 MySQL 中的保留字,因此您必须使用反引号对其进行转义。

Maybe try enclosing the column names with the grave accent?也许尝试用重音将列名括起来?

(`id`,`status`,`key`,`email`)

dont put php variable in '', it will surely work man不要把 php 变量放在''中,它肯定会起作用的人

$db = mysql_query("INSERT INTO `pass_reset` (id,status,key,email) VALUES ('','0',$key,$email)");

Or或者

 $db = mysql_query("INSERT INTO `pass_reset` (id,status,key,email) VALUES ('0',$key,$email)");

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

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