SQLSTATE [42000]:语法错误或访问冲突:1064 phpmyadmin

时间:2017-05-17 04:38:02

标签: php database

我是编程方面的超级新秀。我不确定为什么会出现此错误。我搜索了同样的问题,但他们没有工作。这是完整的错误:

  

错误:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;检查与您的MariaDB服务器版本对应的手册,以便在第3行的'WHERE id ='3''附近使用正确的语法

<?php

if (isset($_POST['LMedit_form'])) {

  include "db.php";

  try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    $stmt = $conn->prepare("UPDATE lmreservation SET name = :name, studentstaffid = :studentstaffid, faculty = :faculty, contactno = :contactno, 
    email = :email, program = :program, participant = :participant, attandance = :attandance, module = :module, date = :date, starttime = :starttime, endtime = :endtime,
    WHERE id = :record_id");

    $stmt->bindParam(':name', $name, PDO::PARAM_STR);
    $stmt->bindParam(':studentstaffid', $studentstaffid, PDO::PARAM_STR);
    $stmt->bindParam(':faculty', $faculty, PDO::PARAM_STR);
    $stmt->bindParam(':contactno', $contactno, PDO::PARAM_STR);
    $stmt->bindParam(':email', $email, PDO::PARAM_STR);
    $stmt->bindParam(':program', $program, PDO::PARAM_STR);
    $stmt->bindParam(':participant', $participant, PDO::PARAM_STR);
    $stmt->bindParam(':attandance', $attandance, PDO::PARAM_STR);
    $stmt->bindParam(':module', $module, PDO::PARAM_STR);
    $stmt->bindParam(':date', $date, PDO::PARAM_STR);
    $stmt->bindParam(':starttime', $starttime, PDO::PARAM_STR);
    $stmt->bindParam(':endtime', $endtime, PDO::PARAM_STR);
    $stmt->bindParam(':record_id', $id, PDO::PARAM_INT);

    $name = $_POST['name'];
    $studentstaffid = $_POST['studentstaffid'];
    $faculty = $_POST['faculty'];
    $contactno = $_POST['contactno'];
    $email = $_POST['email'];
    $program = $_POST['program'];
    $participant = $_POST['participant'];
    $attandance = $_POST['attandance'];
    $module = $_POST['module'];
    $date = $_POST['date'];
    $starttime = $_POST['starttime'];
    $endtime = $_POST['endtime'];
    $id = $_POST['id'];

    $stmt->execute();

    header("Location:LMlist_reservation.php");
    }

    catch(PDOException $e)
    {
        echo "Error: " . $e->getMessage();
    }

    $conn = null;
  }
else {
  echo "Error: You have execute a wrong PHP. Please contact the web administrator.";
  die();
}

?>

2 个答案:

答案 0 :(得分:1)

您在末尾添加了额外的逗号

endtime = :endtime, WHERE id = :record_id

:endtime

之后删除逗号
endtime = :endtime  WHERE id = :record_id 

答案 1 :(得分:1)

之后 $ stmt WHERE 之前删除逗号 字符串:

    $stmt = $conn->prepare("UPDATE lmreservation SET name = :name, studentstaffid = :studentstaffid, faculty = :faculty, contactno = :contactno, 
    email = :email, program = :program, participant = :participant, attandance = :attandance, module = :module, date = :date, starttime = :starttime, endtime = :endtime
    WHERE id = :record_id");