您的SQL语法有错误;检查对应的手册

时间:2013-12-01 02:38:25

标签: php mysql sql

我在这个错误中去了香蕉,你能帮帮我吗?提前谢谢

这是错误您的SQL语法中有错误;查看与您的MySQL服务器版本对应的手册,以便在')值附近使用正确的语法('aaaaaaaa','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');

    }


?>

1 个答案:

答案 0 :(得分:2)

改变这个:

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')

&#34);

对此:

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')");

一点建议:不要将值从$ _POST插入数据库。你必须至少使用函数mysql_real_escape_string()

来清理它