title: insert query using foreach loop receiving Uncaught Error: Call to a member function execute() on boolean
body: <p>I am trying to insert multiple rows at once to my db, I posted a question here the other day <a href="https://stackoverflow.com/questions/37976978/loop-through-result-set-before-inserting-data-into-db?noredirect=1#comment63400846_37976978">see here</a>. Regarding my insert query only insert one row into the db, even if it was necessary for a 2 or more rows of data to be inserted into the DB. Due to the fact this insert query is inserting shopping cart data i am unaware of the number of items a user may insert into the db.</p>
  
  <p>After spending a few days researching i found the method i am now using may be the best way to resolve the issue, this is my first time using a foreach loop, and creating a insert query this way, I am receiving the follow error:</p>
  
  <blockquote>
    <p>Fatal error: Uncaught Error: Call to a member function execute() on boolean </p>
  </blockquote>
  
  <p>Which i am aware means my prepare statement failed, but i was hoping someone could explain or demonstrate where i have gone wrong, as i am trying to learn from my mistakes. I am not sure if it is the way i have created my query or even the way i have executed it.</p>
  
  <p><strong>Code</strong></p>
  
  <pre><code>$_query = "INSERT INTO ord_dets(Order_ID,custmer_ip,Resturant_ID,Resturant_name,City_name,
          Product_Id,Product_Name,Product_Price,item_sub) 
  VALUES ";
          $_query_parts  = array();
          for($x=0;$x&lt;count($OI); $x++){
          $_query_parts  = "('" . $OI[$x] . "', '" . $ip[$x] . "','" . $_SESSION['rest_id'][$x] . "','" . $rest_name[$x] . "',
              '" . $City_name[$x] . "','" . $Product_Id[$x] . "','" . $product_name[$x] . "','" . $prod_price[$x] . "','" . $item_sub[$x] . "')";
          }
         $query_run = $dbc-&gt;prepare($_query);
         echo $_query;
  
          if (!$query_run-&gt;execute()) {
              $insertError = "There was an error inserting data: " . $query_run-&gt;error;
        print "affected rows:" . $query_run-&gt;affected_rows; //how many records affected?         
  
      }
    }
  </code></pre>