3

When I run this code for updating my likedOne column and making it empty ("")....

    $sql11 = $conn->prepare("UPDATE UserData SET likedOne=? WHERE username=?");
    $sql11->bind_param('ss',"",$Username);
    $Username = "netsgets";
    $sql11->execute();

I get this error....

1 Fatal error: Cannot pass parameter 2 by reference in /xxx/xxx/xxx/test.php on line 36. 

The line is....

$sql11->bind_param('ss',"",$Username);

What's wrong?

Ruslan Osmanov
  • 20,486
  • 7
  • 46
  • 60
  • The error message clearly states that the second parameter (`""`) cannot be passed by reference. Only variables can be passed by reference, so you should create a variable, and pass it as the second parameter instead. – Ruslan Osmanov Sep 13 '17 at 02:19

3 Answers3

12

You need to use a variable , bind_param takes only variable not values directly.

   $likedone ="";
   $sql11->bind_param('ss',$likedone,$Username);
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109
1

bind_param(...) expects its param parameters as references. See. That means it might change them (e.g. when they refer to a result of the query). Whenever you pass something as a reference you have to give it a name (sloppy rule of thumb, but makes it easier to explain). In a way this just tells PHP that you care about the potential modification (again simplified). You can use $emptyString = ""; $sql11->bind_param('ss',$emptyString ,$Username);

jh1711
  • 2,288
  • 1
  • 12
  • 20
-2

sorry for my previous answers

you could fix it up by changing

 $sql11->bind_param('ss',"",$Username);

to

$variable ="";
$sql11->bind_param('ss',$variable,$Username);

because bind_param works better with variables

Adeojo Emmanuel IMM
  • 2,104
  • 1
  • 19
  • 28