我想用PHP中的following函数更新表。问题是不接受第二个参数$ work_place,更新失败。这是我第一次使用PHP和mySQL,所以我的知识有点受限。
public function timestampOut($work_done, $work_place)
{
// clean the input to prevent for example javascript within the notes.
$work_done = strip_tags($work_done);
$work_place = strip_tags($work_place);
$userLastTimestampID = $this->getUserLastTimestampID();
$sql = "UPDATE timestamps SET timestamp_work_description = :work_done, timestamp_work_dropdown = :work_place, timestamp_out = now() WHERE timestamp_id = $userLastTimestampID[0] AND user_id = :user_id";
$query = $this->db->prepare($sql);
$query->execute(array(':work_done' => $work_done, ':user_id' => $_SESSION['user_id']));
$count = $query->rowCount();
if ($count == 1) {
return true;
} else {
$_SESSION["feedback_negative"][] = FEEDBACK_NOTE_CREATION_FAILED;
}
// default return
return false;
}
答案 0 :(得分:2)
您只需要在执行调用中将work_place添加到param数组中,如下所示:
$query->execute(array(':work_done' => $work_done, ':work_place' => $work_place, ':user_id' => $_SESSION['user_id']));
答案 1 :(得分:0)
请再次阅读execute
的工作原理。您可能希望像这样使用它:
$query->execute(array(':work_done' => $work_done, ':work_place' => $work_place, ':user_id' => $_SESSION['user_id']));
答案 2 :(得分:0)
尝试替换
$query->execute(array(':work_done' => $work_done, ':user_id' => $_SESSION['user_id']));
与
$query->execute(array(':work_done' => $work_done, ':user_id' => $_SESSION['user_id']), ':work_place' => $work_place);