View Single Post
Old 05-31-2011, 01:18 AM   #2 (permalink)
tony
The Addict
 
tony's Avatar
 
Join Date: Aug 2008
Posts: 336
Thanks: 8
tony is on a distinguished road
Default

That is because you have:

PHP Code:
$query="INSERT INTO orders (ORDER_DESC) VALUES ('".$order."' )";

which when it is looping it is replacing the query. Instead try assemble the query. like this:

PHP Code:
if(count($orders)>0)
{
  $query = 'INSERT INTO orders (ORDER_DESC) VALUES ';
  //you could loop through it
  /*
  foreach($orders as $order)
  {
    $query .= "('".$order."'), ";
  }
  */

  //or just use implode
  $query .= "('".implode("'), ('", $orders)."')";
 
  //if you used the implode function you don't need this next line
  $query = trim(', ', $query).';';
  mysql_query($query) or die ('Error Updating the Database' . mysql_errno());
  echo "Order Successfully Placed";
}

that would create something like this:

SQL Code:
INSERT INTO orders (ORDER_DESC) VALUES ('CSF'), ('LFT'), ('RFR');

which is how you query a mysql database to insert multiple records.

Last edited by tony : 05-31-2011 at 01:24 AM. Reason: a simpler solution
tony is offline  
Reply With Quote