我是编程方面的 super 菜鸟。我不确定为什么会出现这个错误。我搜索过同样的问题,但它们不起作用。这是完整的错误:
Error: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'WHERE id = '3'' at line 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();
}
?>
最佳答案
您在末尾添加了额外的逗号
endtime = :endtime, WHERE id = :record_id
删除:endtime后面的逗号
endtime = :endtime WHERE id = :record_id
关于php - SQLSTATE[42000] : Syntax error or access violation: 1064 phpmyadmin,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44015718/