php 您的 SQL 语法有错误;检查对应的手册
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20308124/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
You have an error in your SQL syntax; check the manual that corresponds
提问by Jayc Zeraval
Im going bananas in this error, can you help me out? thanks in advance
我在这个错误中陷入困境,你能帮我吗?提前致谢
here's the 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 ') values ('aaaaaaaaa','asfasfasas','asfasfasfasf','Male','12/11/2013','' at line 1
这是错误您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取在 ') 附近使用的正确语法 ('aaaaaaaaa','asfasfasas','asfasfasfasf','Male','12/11/2013','' 在第 1 行
<?php
if (isset($_POST['save'])){
$surname=$_POST['surname'];
$firstname=$_POST['firstname'];
$middlename=$_POST['middlename'];
$sex=$_POST['sex'];
$Date_of_Birth=$_POST['Birth_date'];
$birth_place=$_POST['birth_place'];
$citizenship=$_POST['citizenship'];
$Telephone_NO=$_POST['Telephone_NO'];
$Permanent_Address=$_POST['Permanent_Address'];
$Position=$_POST['Position'];
$Classification=$_POST['Classification'];
$fat=$_POST['fat'];
$mot=$_POST['mot'];
$fatadd=$_POST['fatadd'];
$motadd=$_POST['motadd'];
$nino=$_POST['nino'];
$nina=$_POST['nina'];
mysql_query("insert into mrecord (LastName,FirstName,MiddleName,location,sex,Date_of_Birth,birth_place,citizenship, Telephone_NO, Permanent_Address,Position,Classification,fat,mot,fatadd,motadd,nino,nina,)
values ('$surname','$firstname','$middlename','$sex','$Date_of_Birth','$birth_place', '$citizenship','$Telephone_NO','$Permanent_Address','$Position','$Classification','$fat','$mot','$fatadd','$motadd','$nino','$nina')
") or die(mysql_error());
header('location:emp_profiles.php');
}
?>
回答by Paul Denisevich
Change this:
改变这个:
mysql_query("insert into mrecord (LastName,FirstName,MiddleName,location,sex,Date_of_Birth,birth_place,citizenship, Telephone_NO, Permanent_Address,Position,Classification,fat,mot,fatadd,motadd,nino,nina,) values ('$surname','$firstname','$middlename','$sex','$Date_of_Birth','$birth_place', '$citizenship','$Telephone_NO','$Permanent_Address','$Position','$Classification','$fat','$mot','$fatadd','$motadd','$nino','$nina')
");
");
To this:
对此:
mysql_query("insert into `mrecord` (`LastName`, `FirstName`, `MiddleName`, `location`, `sex`, `Date_of_Birth`, `birth_place`, `citizenship`, `Telephone_NO`, `Permanent_Address`, `Position`, `Classification` , `fat`, `mot`, `fatadd`, `motadd`, `nino`, `nina`) values ('$surname', '$firstname', '$middlename', '$sex', '$Date_of_Birth', '$birth_place', '$citizenship', '$Telephone_NO', '$Permanent_Address', '$Position', '$Classification', '$fat', '$mot', '$fatadd', '$motadd', '$nino', '$nina')");
A little advice: DO NOT insert values into database from $_POST. You have to clean it up at least with function mysql_real_escape_string()
一点建议:不要从 $_POST 将值插入数据库。你必须至少用函数来清理它mysql_real_escape_string()

