This is a useful function that I wrote to insert an array into a table in your database.

function insert_array($table, $data) {  
 $cols = '(';
 $values = '(';
 foreach ($data as $key=>$value) {
  $value = addslashes($value);
  $cols .= "$key,";  
  $values .= "'$value',";  
 }
 $cols = rtrim($cols, ',').')';
 $values = rtrim($values, ',').')';  
 $sql = "INSERT INTO $table $cols VALUES $values";
 mysql_query($sql) or die(mysql_error());
 return mysql_insert_id();
}

Here is an example of using this code:

<?php
$arr = array('title' => $_POST['title'], 'product_code' => $_POST['product_code'], 'description' => $_POST['description'], 'price' => $_POST['price']);
$product_id = insert_array("products", $arr);
?>