Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP and MySQLi - Cannot pass parameter 2 by reference in [duplicate]

Tags:

php

mysqli

I am trying to make a function which will check update and insert some data but I am having an issue in the first step where the $stmt->bind_param is saying that is not passing parameters by reference or something like that.

I have attached below the 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");
            }
        }

    }
like image 846
Sadi Qevani Avatar asked Jan 28 '13 16:01

Sadi Qevani


1 Answers

You cannot do this in mysqli:

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

The 0 needs to be a variable.

Try this:

$zero = 0;
$stmt->bind_param("ii",$zero,$victimiid);
like image 107
Naftali Avatar answered Nov 15 '22 13:11

Naftali