I'm inserting data from a file that has 18 columns, the table that I would like to insert it into has 20 columns. 2 of those columns already contain data. How do I go about inserting the file into the table without overwriting the existing data.
below is a example of the code. note $line .= ',,'
is appending two columns because the update wont' work unless the columns match the exact table size of 20 columns. But the $line .= ',,'
overwrites the data already inserted. What do i do?
$fcontents = file('data.txt');
if(mysql_error())
echo mysql_error();
for($i=0; $i<sizeof($fcontents); $i++)
{
//strip out double quotes
$line = ereg_replace('"','',trim($fcontents[$i]));
$line .= ',,';
//strip replace semi-colon with blank spaces
$line = ereg_replace(';',' ',$line);
//single quote in parts records breaks replace code, removing single quote...
$line = ereg_replace("'",'',$line);
//breaks apart the tab delimited row into a array
$arr = explode(",", $line);
//add comma deliminted data back
mysql_query("REPLACE INTO products VALUES ('". implode("','", $arr) ."')");
}