Multi Dimensional Array to MySQL database

I have a database with 3 fields id, article, category.

There are a series of input boxes for article name and a corresponding select box for category. I am trying to write the article name and the category to a record for each group.

Here is the array info:

Array ( 
      		[article] => 
      			Array ( 
      			[0] => Black Plaid Western Shirt
      			[1] => Dogfish Head T-shirt
      			[2] => Old Navy Bootcut Jeans
      			[3] => Cowboy Boots )
      		
      		[category] => 
      			Array ( 
      			[0] => Dress Shirt
      			[1] => T-Shirt
      			[2] => Jeans
      			[3] => Footwear ) 
      		)

And here is my insert statement:

 foreach ($_POST['wardrobe'] as $key => $value) {
	  $sql = "insert into worn(userid,eventid,article,category) values('$userid','$eventid','".$value['article']."','".$value['category']."')";
	  $result = mysql_query($sql);
	  }

Thanks.

Thanks. That worked perfectly. I appreciate your help good sir.

Thanks I will give that a try and report back.

Hi
You cannot insert both category and article in the same loop. looping an array moves one by one. So if your article and category count is always same as you have shown in the code above then i have a solution for it.


//note if the count of the article and category is same.
//otherwise you have to break the array and insert it.
$abc=array("article" =>
				array ( 
                  "0" => "Black Plaid Western Shirt",
                  "1" => "Dogfish Head T-shirt",
                  "2" => "Old Navy Bootcut Jeans",
                  "3" => "Cowboy Boots" ),     
      		"category" => 
                  array ( 
                  "0" => "Dress Shirt",
                  "1" => "T-Shirt",
                  "2" => "Jeans",
                  "3" => "Footwear" )
);

for($i=0;$i<count($abc['category']);$i++){
	echo $abc['category'][$i];
	echo $abc['article'][$i];
        //insert it here.
 }