user1723760 user1723760 - 1 year ago 374
SQL Question

PHP error: "Cannot pass parameter 2 by reference"

I just need help on this PHP error which I do not quite understand:

Fatal error: Cannot pass parameter 2 by reference in /web/stud/openup/inactivatesession.php on line 13




$createDate = mktime(0,0,0,09,05,date("Y"));
$selectedDate = date('d-m-Y', ($createDate));

$sql = "UPDATE Session SET Active = ? WHERE DATE_FORMAT(SessionDate,'%Y-%m-%d' ) <= ?";
$update = $mysqli->prepare($sql);
$update->bind_param("is", 0, $selectedDate); //LINE 13


What does this error mean? How can this error be fixed?

Answer Source

The error means that the 2nd argument is expected to be a reference to a variable.

Since you are not handing a variable but an integer of value 0, it generates said error.

To circumvent this do:

$update->bind_param("is", $a = 0, $selectedDate);  //LINE 13

In case you want to understand what is happening, as opposed to just fixing your Fatal error, read this:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download