I am getting this error from MySQL:
我从MySQL得到这个错误:
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 'Details
(title, first, last, NRIC, po' at line 1
Here is the code:
这是代码:
<?php
$link = mysql_connect("localhost", "root", "");
if (!$link) { die('Could not connect: ' . mysql_error()); }
$db_selected = mysql_select_db(Membership, $link);
if (!$db_selected) { die('Can\'t use' . Membership . ':' . mysql_error()); }
$value1 = $_POST["title"];
$value2 = $_POST["first"];
$value3 = $_POST["last"];
$value4 = $_POST["NRIC"];
$value5 = $_POST["birthdate"];
$value6 = $_POST["birthmonth"];
$value7 = $_POST["birthyear"];
$value8 = $_POST["address"];
$value9 = $_POST["postal"];
$value10 = $_POST["genderSelect"];
$value11 = $_POST["contact"];
$value12 = $_POST["email"];
$value13 = $_POST["enter"];
$value14 = $_POST["password"];
$value15 = $_POST["Updates"];
$value16 = $_POST["Terms"];
$value17 = $_POST["submit_but"];
$value18 = $_POST["status"];
$sql = "INSERT INTO Member Details (title, first, last, NRIC, birthdate, birthmonth, birthyear, address, postal, genderSelect, contact, email, enter, password, Updates, Terms, submit_but, status) VALUES ('$value', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12', '$value13', '$value14', '$value15', '$value16', '$value17', '$value18')";
if (!mysql_query($sql)){ //The error is thrown here
die('Error: ' . mysql_error());
}
mysql_close();
?>
3 个解决方案
#1
14
Your problem lies here:
你的问题在于:
INSERT INTO Member Details ...
Because you have a space there, it thinks Member
is the table name and Details
is extraneous, hence the error.
因为那里有空格,所以它认为Member是表名,而Details是无关的,因此错误。
If your table is Member Details
, you need to enclose it within back ticks:
如果您的表是会员详细信息,则需要将其附在后面的时间范围内:
INSERT INTO `Member Details` ...
I'm actually not that big a fan of spaces in SQL table names (or filesystem file names for that matter). In this particular case, I believe MemberDetails
(or Member_Details
, member_details
and probably others) is just as readable, without requiring the use of backticks scattered throughout your code.
我实际上并不是SQL表名(或文件系统文件名)空间的忠实粉丝。在这种特殊情况下,我相信MemberDetails(或Member_Details,member_details和其他可能的东西)同样可读,而不需要使用分散在整个代码中的反引号。
#2
5
try mark (``) for each field name so the result may be like this
为每个字段名称尝试标记(``),结果可能是这样的
"INSERT INTO `Member Details` (`title`, `first`, `last`, `NRIC`, `birthdate`, `birthmonth`, `birthyear`, `address`, `postal`, `genderSelect`, `contact`, `email`, `enter`, `password`, `Updates`, `Terms`, `submit_but`, `status`)
VALUES ('$value', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12', '$value13', '$value14', '$value15', '$value16', '$value17', '$value18')";
#3
4
Your insert syntax is wrong. If member is the table name them it should be something like the following
您的插入语法错误。如果member是表名,那么它应该类似于以下内容
INSERT INTO Member (title, first, last, NRIC, birthdate, birthmonth, birthyear, address, postal, genderSelect, contact, email, enter, password, Updates, Terms, submit_but, status) VALUES ('$value', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12', '$value13', '$value14', '$value15', '$value16', '$value17', '$value18')
#1
14
Your problem lies here:
你的问题在于:
INSERT INTO Member Details ...
Because you have a space there, it thinks Member
is the table name and Details
is extraneous, hence the error.
因为那里有空格,所以它认为Member是表名,而Details是无关的,因此错误。
If your table is Member Details
, you need to enclose it within back ticks:
如果您的表是会员详细信息,则需要将其附在后面的时间范围内:
INSERT INTO `Member Details` ...
I'm actually not that big a fan of spaces in SQL table names (or filesystem file names for that matter). In this particular case, I believe MemberDetails
(or Member_Details
, member_details
and probably others) is just as readable, without requiring the use of backticks scattered throughout your code.
我实际上并不是SQL表名(或文件系统文件名)空间的忠实粉丝。在这种特殊情况下,我相信MemberDetails(或Member_Details,member_details和其他可能的东西)同样可读,而不需要使用分散在整个代码中的反引号。
#2
5
try mark (``) for each field name so the result may be like this
为每个字段名称尝试标记(``),结果可能是这样的
"INSERT INTO `Member Details` (`title`, `first`, `last`, `NRIC`, `birthdate`, `birthmonth`, `birthyear`, `address`, `postal`, `genderSelect`, `contact`, `email`, `enter`, `password`, `Updates`, `Terms`, `submit_but`, `status`)
VALUES ('$value', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12', '$value13', '$value14', '$value15', '$value16', '$value17', '$value18')";
#3
4
Your insert syntax is wrong. If member is the table name them it should be something like the following
您的插入语法错误。如果member是表名,那么它应该类似于以下内容
INSERT INTO Member (title, first, last, NRIC, birthdate, birthmonth, birthyear, address, postal, genderSelect, contact, email, enter, password, Updates, Terms, submit_but, status) VALUES ('$value', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12', '$value13', '$value14', '$value15', '$value16', '$value17', '$value18')