Mårten
Mårten

Reputation: 1

PHP how to use muliple parameters and update mySQL table with them

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;
    }

Upvotes: 0

Views: 60

Answers (3)

PGBI
PGBI

Reputation: 710

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);

Upvotes: 0

Alexander
Alexander

Reputation: 20224

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']));

Upvotes: 0

Brian Driscoll
Brian Driscoll

Reputation: 19635

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']));

Upvotes: 2

Related Questions