Hi, here is the code. I can not understand the query part. If my .csv file have ID, Name, Email, Subject how i put this into query? Please help me out.
[code]$columnArray = array();
$dataArray = array();
$firstRule = true;
while ($data = fgetcsv ($handle, 1000, “,”))
{
if($firstRule)
{
foreach($data as $columnName)
{
$columnArray[] = $columnName;
}
$firstRule = false;
}
else
{
$rule = array();
for($i = 0; $i < count($data) ; $i++)
{
$rule[$columnArray[$i]] = $data[$i];
}
$dataArray[] = $rule;
}
}
foreach($dataArray as $data)
{
$query=“INSERT INTO Import_CopiersandPrinters_Canon_Raw_Data
set Account Name
= '”.htmlspecialchars($data[‘Account Name’],ENT_QUOTES)."’,
Account Number
= ‘".htmlspecialchars($data[1],ENT_QUOTES)."’,
Does Business As (DBA)
= ‘".htmlspecialchars($data[‘Does Business As (DBA)’],ENT_QUOTES)."’,
Shipping City
= ‘".htmlspecialchars($data[‘Shipping City’],ENT_QUOTES)."’,
…
…
…
file_name
= ‘".$new_file_name."’,
file_date
= ‘".date(‘Y-m-d H:i:s’)."’";
mysql_query($query) or die(mysql_error());
//Note that this would't reach when an error occured, because you used `or die`. You should use `or print` when you want to continue your code
if (mysql_error() <> "")
{
fputcsv($output, $data);
$error_count++;
}
else
{
$row_count = $row_count + 1;
}
$total = $total+1;
}[/code]