import content from csv to mysql database
<p>There is a mysql database named: <code>example</code> which has a table named: <code>products</code> it have fields: <code>products_model</code> and <code>products_image</code>. the model field is unique.</p>

<p>now i have a csv file named <code>data.csv</code>. which have two column products_model and <code>products_image</code>.i use the following code. but it doesn't import the data into the database.what's wrong with my code?</p>

<pre><code>    $fp = fopen("data.csv","r");
$length = 4096; //have to be optional length
$fildDelineate = ',' ;//or "|" declare what you need
$dbhost="localhost";
$dbname="zencartone";
$dbuser="root";
$dbpass="";
$link  = mysql_connect($dbhost,$dbuser,$dbpass);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname);

$databasetable  = 'products';

$counter = 1;//to omission first row if it is table headers

while($line = fgetcsv($fp,$length,$fildDelineate)){
    foreach($line as $key=&gt;$value){
        //for example insert in 3 column
        $importSQL = "insert into $databasetable  (products_model, products_image) values('$line[0]','$line[1]')";
        mysql_query($importSQL) or die(mysql_error());
    }
    $counter++;
}
fclose($fp);
</code></pre>

<p>data.csv:</p>

<p>have two column:</p>

<pre><code>products_model  products_image
MG200MMS    dress/201247561673.jpg
MG400-32MB  dress/2012471141673.jpg
MSIMPRO dress/201247741673.jpg
DVD-RPMK    dress/2012471831673.jpg
DVD-BLDRNDC dress/2012474221673.jpg
DVD-MATR    dress/201112132056773.jpg
</code></pre>
