0

I am trying to update some data in my DB via:

if($stmt = $connection->prepare("UPDATE `booking` SET status = ?, datecreated = ? WHERE day = ? AND timeSlot = ?")){
    $stmt->bind_param('ssss', 'processing', 'now()', $results[0]['timeSlot'], $results[0]['day']);
    $stmt->execute();
    $stmt->close();
    echo 'Updated';
}

When I run this I get the following error:

Fatal error: Cannot pass parameter 2 by reference

The column datecreated is a datetime type.

I have tried now() and 'now()' and date('Y-m-d H:i:s') all 3 give me the same error.

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87
user979331
  • 11,039
  • 73
  • 223
  • 418

1 Answers1

4

You need to bind variables that can be referenced. If they aren't variables then put them directly in the query:

if($stmt = $connection->prepare("UPDATE `booking` SET status = 'processing', datecreated = NOW() WHERE day = ? AND timeSlot = ?")){
    $stmt->bind_param('ss', $results[0]['timeSlot'], $results[0]['day']);
    $stmt->execute();
    $stmt->close();
    echo 'Updated';
}

Or I guess you could do $booking = 'processing'; and $datecreated = 'NOW()'; and binds those variables if you must.

AbraCadaver
  • 78,200
  • 7
  • 66
  • 87