我有一个数据库,我正在尝试更新它的一行,但我一直收到这个错误。在以前的程序中,我使用相同的功能,所以我看不出有什么问题,这让我很生气!如果有人能看到任何东西或帮助我,我将不胜感激!
这是更新功能:
public function update($member){
if ($member == null){
throw new Exception("Member ID Required"); }
$id = $member->getId();
if ($id == null){
throw new Exception("Member ID Required");
}
$sql = "UPDATE member SET
firstName = :firstName,
lastName = :lastName,
dob = :dob,
email = :email,
gender = :gender,
skillLevel = :skillLevel,
Where id = :id";
$params = array(
'id' => $member->getId(),
'firstName' => $member->getFirstName(),
'lastName' => $member->getLastName(),
'dob' => $member->getDOB(),
'email' => $member->getEmail(),
'gender' => $member->getGender(),
'skillLevel' => $member->getSkillLevel(),
);
$stmt = $this->link->prepare($sql);
$status = $stmt->execute($params);
if ($status != true){
$errorInfo = $stmt->errorInfo();
throw new Exception("Could Not Add Member: " . $errorInfo[2]);
}
return $stmt->rowCount();
}
以下是从
获取数据的编辑页面<?php
require_once('member.php');
require_once('MemberDAO.php');
require_once('editFormValidator.php');
$validator = new editFormValidator();
if ($validator->validate($_POST)){
$i = $_POST['memberID'];
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$dob = $_POST['dob'];
$email = $_POST['email'];
$gender = $_POST['gender'];
$skillLevel = $_POST['skillLevel'];
$skillLevelString = implode(", ", $skillLevel);
$member = new Member ($i,$firstName, $lastName, $dob, $email, $gender, $skillLevelString);
$dao = new MemberDAO();
$dao->update($member);
header ('Location: viewMember.php');
}
else{
require_once 'editMember.php';
}
?>
这是完整的错误:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 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 'Where id = '4'' at line 8' in /Applications/XAMPP/xamppfiles/htdocs/ChessClub/MemberDAO.php:115 Stack trace: #0 /Applications/XAMPP/xamppfiles/htdocs/ChessClub/MemberDAO.php(115): PDOStatement->execute(Array) #1 /Applications/XAMPP/xamppfiles/htdocs/ChessClub/edit.php(20): MemberDAO->update(Object(Member)) #2 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/ChessClub/MemberDAO.php on line 115
答案 0 :(得分:1)
这里有一个多余的逗号:
skillLevel = :skillLevel,