- 此问题在此处已有答案**:
SQLSTATE[HY093]: Invalid parameter number: parameter was not defined(4个答案)
12小时前关门了。
我是PDO的新手。我被卡住了,现在我在这里。我尝试了基本原油
PDO和获取错误无效参数:未定义参数
从更新部分。请帮助我?
public function update_by_id($data) {
$id = $data['student_id'];
$name = $data['student_name'];
$department = $data['department'];
$email = $data['email_address'];
$city = $data['city'];
try {
$sql = "UPDATE tbl_student SET student_name=:name, department=:department, email_address=:email, city=:city WHERE student_id='$id' ";
$stmt = $this->db_conn->prepare($sql);
$stmt->bindParam(':name', $name, PDO::PARAM_STR);
$stmt->bindParam(':department', $department, PDO::PARAM_STR);
$stmt->bindParam(':email_address', $email, PDO::PARAM_STR);
$stmt->bindParam(':city', $city, PDO::PARAM_STR);
if($stmt->execute()) {
header('Location: view_student.php');
}
else {
echo $this->db_conn->errorInfo();
}
} catch (Exception $e) {
echo $e->getMessage();
}
}
2条答案
按热度按时间umuewwlo1#
使用
:email
代替:email_address
因为在查询中绑定
email_address=:email,
您也可以在代码中绑定
$id
tjjdgumg2#
变更
至
当你使用