Correction status:Uncorrected
Teacher's comments:
<?php require 'mysqli_connect2.php'; $sql = "UPDATE IGNORE staff SET name=?,sex=?,age=?,salary=? WHERE staff_id=?;";// 准备 sql 语句 $stmt = mysqli_stmt_init($db);//创建并初始化预处理对象stmt mysqli_stmt_prepare($stmt, $sql);//用stmt对象处理当前预处理语句 mysqli_stmt_bind_param($stmt, 'siiii', $name, $sex, $age, $salary, $staff_id);// 变量与语句中的占位符进行绑定 $staff_id = 18; $name = '八荒六唯我独尊功9'; $sex = 0; $age = 99; $salary = 99999; mysqli_stmt_execute($stmt);//执行 sql 语句 echo '更新成功,主键id是:'.$staff_id; mysqli_stmt_close($stmt); mysqli_close($db); ?>
<?php require 'mysqli_connect2.php'; $sql = "DELETE FROM staff WHERE staff_id=?";// 准备 sql 语句 $stmt = mysqli_stmt_init($db);//创建并初始化预处理对象stmt mysqli_stmt_prepare($stmt, $sql);//用stmt对象处理当前预处理语句 mysqli_stmt_bind_param($stmt, 'd', $staff_id);// 变量与语句中的占位符进行绑定 $staff_id = 21; mysqli_stmt_execute($stmt);//执行 sql 语句 echo '删除成功,主键id是:'.$staff_id; mysqli_stmt_close($stmt);//注销预处理对象 mysqli_close($db);//关闭数据连接 ?>
WHERE 语句后面的变量绑定直接在参数后面加一个即可mysqli_stmt_bind_param($stmt, 'siiii', $name, $sex, $age, $salary, $staff_id);