我是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();
}
}
答案 0 :(得分:1)
而不是:email
使用 $stmt->bindParam(':email', $email, PDO::PARAM_STR);
email_address=:email,
因为您的查询中的绑定$id
您也可以在代码中绑定$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', $email, PDO::PARAM_STR);
$stmt->bindParam(':city', $city, PDO::PARAM_STR);
$stmt->bindParam(':id', $id, PDO::PARAM_INT);
{{1}}
答案 1 :(得分:0)
更改
$stmt->bindParam(':email', $email, PDO::PARAM_STR);
要
.., email_address=:email,...
正在使用
<video id="myVideo" src = "./play.mp4" autoplay loop></video>