title: Prepared Statement Cannot pass parameter 2 by reference.
body: <p>Getting the following error:</p>
  
  <blockquote>
    <p>Fatal error: Cannot pass parameter 2 by reference in
    C:\xampp\htdocs\ppa\php\process_images.php on line 29</p>
  </blockquote>
  
  <p>Simply trying to update a database record, the following debug code</p>
  
  <pre><code>$id = (int)$x;
  echo $id.". Type: ".gettype($id);
  </code></pre>
  
  <p>produces this: 4. Type: integer
  So the variable is the correct type. </p>
  
  <p>Here is my code</p>
  
  <pre><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-&gt;prepare("UPDATE images SET dodelete = ? WHERE id = ?")) {
              $id = (int)$x;
              echo $id.". Type: ".gettype($id);
              $stmt-&gt;bind_param("ii", 1, $id);   &lt;---- line 29
              $stmt-&gt;execute();
              $stmt-&gt;close();
          } else {
              echo "Unable to delete image!";
          }
      }
  }
  </code></pre>
  
  <p>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. </p>