I need to insert the following array into a mysql table with columns name,title,url,logo. I created the table and wrote a query to transfer the array. But it was inserting the last line of the array and leaving remaining... plz help me... this is my array
$con = mysql_connect("localhost","","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("media", $con);
$featured = array();
$featured[] = array('name' => '', 'title' => '', 'url' => '', 'logo' => '');
$featured[] = array('name' => '', 'title' => '', 'url' => '', 'logo' => '');
$featured[] = array('name' => '', 'title' => '', 'url' => '', 'logo' => '');
$featured[] = array('name' => '', 'title' => '', 'url' => '', 'logo' => '');
$sql = "INSERT INTO featured";
$sql .= " (`".implode("`, `", array_keys($featured))."`)";
$sql .= " VALUES ('".implode("', '", $featured)."') ";
$result = mysql_query($sql) or die(mysql_error());
foreach()loop. We assume all the array values have already been escaped viamysql_real_escape_string()...".implode(",", array_keys($featured)).")"; // implode values of $featured... $sql .= " VALUES ('".implode("', '", $featured)."') "; // execute query... $result = mysql_query($sql) or die(mysql_error()); }$sqlinside the loop. Use a different index:foreach ($featured as $feature)