title: How do I insert an array of id into database MySQL?
body: <p>I'm trying to insert an array of IDs into a database table, but at the moment it only inserts 1 row when it's meant to do multiple rows. My array of IDs contains just (filmid) Does anyone know what the problem is?</p>
  
  <pre><code>$pm = "2";
  $id = "2";             
  
  if($stmt1-&gt;execute())
  {
      $films=array();
      foreach($_SESSION['products'] as $key=&gt;$product)
      {
          array_push($films, $product['filmid']);
          $f_id  = implode(",", $films);
          $stmt2 = $this-&gt;conn-&gt;prepare("INSERT INTO `filmPurchase` (`fpid`, `payid`, `filmid`, `shopid`, `custid`, `price`) VALUES (NULL, :id, :f_id, :pm, :pm, '8')");
          $stmt2-&gt;bindParam('pm',$pm);
          $stmt2-&gt;bindParam('id',$id);
          $stmt2-&gt;bindParam('f_id',$f_id);
          $stmt2-&gt;execute();
      }
  
  }
  </code></pre>
  
  <p>I've tried to loop over the array with:</p>
  
  <pre><code>foreach($_SESSION['products'] as $key=&gt;$product)
  {
      var_dump($key);
      var_dump($product);
  }
  </code></pre>
  
  <p>This is what outputted:</p>
  
  <pre><code>int(29) array(4) { ["qty"]=&gt; int(1) ["filmtitle"]=&gt; string(45) "The Lord of 
  the Rings: The Return of the King" ["filmid"]=&gt; string(2) "29" ["price"]=&gt; 
  float(6.99) } 
  </code></pre>