2

Getting the following error:

Fatal error: Cannot pass parameter 2 by reference in C:\xampp\htdocs\ppa\php\process_images.php on line 29

Simply trying to update a database record, the following debug code

$id = (int)$x;
echo $id.". Type: ".gettype($id);

produces this: 4. Type: integer So the variable is the correct type.

Here is my code

if (isset($_POST['delete'])) {
    //Delete the image, first update the database, then move the image to a new folder. 
    foreach($_POST['product'] as $x) {
        if ($stmt = $mysqli->prepare("UPDATE images SET dodelete = ? WHERE id = ?")) {
            $id = (int)$x;
            echo $id.". Type: ".gettype($id);
            $stmt->bind_param("ii", 1, $id);   <---- line 29
            $stmt->execute();
            $stmt->close();
        } else {
            echo "Unable to delete image!";
        }
    }
}

At first I was binding the $x variable directly from the foreach statement, which I thought was the issue as the error says it can't pass parameter by reference, but as you can see I made a new variable $id.

1
  • Where is the processimage.php code?
    – Nouphal.M
    Jan 7, 2014 at 18:26

1 Answer 1

4
$stmt->bind_param("ii", 1, $id);
                     ---^

It's because 1 is not a parameter, it's an integer. You'll need to use bindValue instead.

1
  • 1
    Ah thanks, I changed it to $deletedVal = 1; $stmt->bind_param("ii", $deletedVal, $id); Jan 7, 2014 at 18:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.