PHP and MySQLi - it is not possible to pass parameter 2 by reference in

I am trying to make a function that will check for updates and insert some data, but I have a problem in the first stage, where $ stmt-> bind_param says that it does not pass parameters by reference or something like that.

I searched through the Internet, but there was nothing around, so I do not know what to do with it.

I added a function code:

public function killTarget($killerid,$victimiid,$victimcode) { if ($this->checkUsercode($victimcode,$victimiid)) { $stmt = $this->_db->prepare("UPDATE users SET status =? WHERE user_id =?"); $stmt->bind_param("ii",0,$victimiid); if ($stmt->execute()) { $stmt->store_result(); $stmt->fetch(); $stmt = $this->_db->prepare("SELECT victim_id FROM target WHERE killer_id = ?"); $stmt->bind_param("i",$victimiid); if ($stmt->execute()) { $stmt->store_result(); $stmt->bind_result($targetid); $stmt->fetch(); $stmt = $this->_db->prepare("INSERT INTO target (killer_id, victim_id) VALUES (?,?)"); $stmt->bind_param("ii",$killerid,$targetid); if ($stmt->execute()) { $stmt->store_result(); $stmt->fetch(); $stmt->close(); } } } else { Main::setMessage("targets.php",$this->_db->error,"alert-error"); } } } 

Good any suggestion appreciated.

thanks

+7
source share
3 answers

You cannot do this in mysqli:

 $stmt->bind_param("ii",0,$victimiid); 

0 must be a variable.

Try the following:

 $zero = 0; $stmt->bind_param("ii",$zero,$victimiid); 
+22
source

Make 0 a variable or include it directly in your query.

 $zero = 0; $stmt->bind_param("ii", $zero, $victimiid); 
+8
source

Beware! mysqli_stmt::bind_param takes a reference to a variable, not a constant value. Therefore, you need to create a variable to hold this 0 , and then reference that variable.

 $i = 0; $stmt->bind_param("ii", $i, $victimiid); 
+7
source

All Articles