问题描述:

Im tying to update a table with the followning function in PHP. The problem is that the second parameter $work_place is not accepted and the update fails. This is my first time working with PHP and mySQL so my knowledge is a bit limited.

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;

}

网友答案:

You just need to add work_place to the param array in your execute call, like so:

$query->execute(array(':work_done' => $work_done, ':work_place' => $work_place, ':user_id' => $_SESSION['user_id']));
网友答案:

Please read again how execute works. You would want to use it like this:

$query->execute(array(':work_done' => $work_done, ':work_place' => $work_place, ':user_id' => $_SESSION['user_id']));
网友答案:

Try to replace

$query->execute(array(':work_done' => $work_done, ':user_id' => $_SESSION['user_id']));

with

$query->execute(array(':work_done' => $work_done, ':user_id' => $_SESSION['user_id']), ':work_place' => $work_place);
相关阅读:
Top