我是Android的新手。我正在尝试从本地服务器获取一些数据。我的查询在phpMyAdmin上运行完美,但是我在api中遇到错误。我对Php知之甚少,所以没有得到问题所在。
代码:
public function saveUserProgress($user_id,$course_id,$topic_id,$quiz_marks){
$output = $this->con->prepare("INSERT INTO user_progress (user_id, course_id, topic_id,quiz_marks)
VALUES (?, ?, ?,?)
ON DUPLICATE KEY UPDATE
user_id=?, course_id=?, topic_id=?, quiz_marks = quiz_marks + ?");
$output->bind_param("iiii",$user_id,$course_id,$topic_id,$quiz_marks);
if($output->execute()){
return PROGRESS_SAVED;
}else{
return ERROR_OCCUR;
}
}
错误:
{"error":true,"message":403}
Warning: mysqli_stmt::bind_param(): Number of variables doesn't match number of parameters in prepared statement
答案 0 :(得分:4)
如果您说过自己的唯一密钥是user_id
和course_id
,那么您就不需要更新重复密钥。您只需要更新其余2个值。与您要添加的4个一起,它会构成6个占位符,因此您需要绑定6个变量。
$output = $this->con->prepare("INSERT INTO user_progress (user_id, course_id, topic_id,quiz_marks)
VALUES (?, ?, ?, ?)
ON DUPLICATE KEY UPDATE
topic_id=?, quiz_marks = quiz_marks + ?");
$output->bind_param("iiiiii", $user_id, $course_id, $topic_id, $quiz_marks, $topic_id, $quiz_marks);
答案 1 :(得分:-1)
您期望的参数比试图绑定的数量更多。您必须处理查询中的每个问号。