【问题标题】:You have an error in your SQL syntax; check the manual that corresponds您的 SQL 语法有错误;检查相应的手册
【发布时间】:2013-12-01 02:38:25
【问题描述】:

这个错误我要疯了,你能帮帮我吗?提前致谢

这是错误您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以获取正确的语法,以便在第 1 行附近使用 ') 值 ('aaaaaaaaa','asfasfasas','asfasfasfasf','Male','12/11/2013',''

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

    }


?>

【问题讨论】:

  • ..,nina,) 是错误的。同样使用mysql(已弃用,使用mysqli或PDO)和not using placeholders也是非常错误的。
  • 哈哈修复它:D但它显示另一个错误?列计数与第 1 行的值计数不匹配
  • 通过使用外部变量构建 SQL 语句,您很容易受到 SQL 注入攻击。 此外,任何带有单引号的输入数据,例如 " O'Malley”,会炸毁你的 SQL 查询。请了解如何使用参数化查询(最好使用 PDO 模块)来保护您的 Web 应用程序。 bobby-tables.com/php 有一些示例可以帮助您入门,this question 有很多详细示例。

标签: php mysql sql


【解决方案1】:

改变这个:

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

");

到这里:

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

来清理它

【讨论】:

  • 另外,请注意某些 SQL 字段是被禁止的,我尝试了一段时间将一个值插入一个名为 'create' 的字段:/
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-06-21
  • 1970-01-01
  • 1970-01-01
  • 2017-09-20
  • 1970-01-01
相关资源
最近更新 更多