0

Simple query to insert record in table but for some reason I am getting this error

Cannot pass parameter 2 by reference in error.

I am not sure why. I tried almost 2 hours but not able to fix it.

$pid = '5';
$ip_add = '127.0.0.1';

$result = $mysqli->prepare("INSERT INTO profile_view(profile_id, ip_address) VALUES (?, ?)");
$result->bind_param("is", $pid, $ip_add);
$result->execute();
$result->store_result();

if($result){
    echo 'Success';
}

Database design is as follows.

ID - BigInt - Auto Increment
profile_id - BigInt
Date - CURRENT_TIMESTAMP
ip_address - VARCHAR 100

Why would I get this error?

halfer
  • 19,824
  • 17
  • 99
  • 186
Roxx
  • 3,738
  • 20
  • 92
  • 155
  • For what line this message? – u_mulder May 09 '17 at 19:47
  • You're sending PID as an integer, but it's declared as a string. Try $pid = 5 without quotes, or changing the i to an s – clearshot66 May 09 '17 at 19:55
  • 1
    @clearshot66 It doesn't matter. MySQL is smart enough to convert a string to an integer. This isn't a PHP datatype issue – Machavity May 09 '17 at 20:00
  • @Machavity then what is it? – clearshot66 May 09 '17 at 20:01
  • You are clearly shortening what you are actually doing. If you hard code a value in the `bind_param` call instead of using a variable, you will get this error. My guess is you simplified the code you are actually using, and in turn, you hid the issue from us. – Jeremy Harris May 09 '17 at 20:01
  • 1
    @clearshot66 The issue is with [bind_param](http://php.net/manual/en/mysqli-stmt.bind-param.php) (read the second Note block). He's not passing a variable, but the code he's got here has variables so it should work as written. I suspect there's more code we've not been given – Machavity May 09 '17 at 20:04
  • @Machavity i am getting error on bind_param line as per firebug. regarding $ip_add i am using $ip_add = $_SERVER['REMOTE_ADDR']; i checked and found both variable have the value. But it is still failing. – Roxx May 10 '17 at 02:32
  • got it. There was typo in $ip_add. That is the reason it was failing. – Roxx May 10 '17 at 02:38

0 Answers0