Hi I am trying to import a bunch of values from a txt file, separated by the | Pipe, but I keep getting the error "Column count doesn't match value count at row 1", so some help would be appreciated.
The data is in the following format:
ProductID|Name|MerchantID|Merchant|Link|Thumbnail|BigImage|Price|RetailPrice|Category|SubCategory|Description|Custom1|Custom2|Custom3|Custom4|Custom5|LastUpdated
The database has the same structure (just renamed a few fields).
The PHP code is as follows.
<?php
include "connect.php";
if(isset($_POST['submit']))
{
$filename=$_POST['filename'];
$handle = fopen("$filename", "r");
while (($data = fgetcsv($handle, 1000, "|")) !== FALSE)
{
$import="INSERT into products(PID,pName,mID,pMerchant,pLink,pThumb,pImage,pPrice,pRetailPrice,pMainCat,pSubCat,pDescription,pCustom1,pCustom2,pCustom3,pCustom4,pCustom5,LastUpdate) values('$data[0]'|'$data[1]'|'$data[2]'|'$data[3]'|'$data[4]'|'$data[5]'|'$data[6]'|'$data[7]'|'$data[8]'|'$data[9]'|'$data[10]'|'$data[11]'|'$data[12]'|'$data[13]'|'$data[14]'|'$data[15]'|'$data[16]'|'$data[17]')";
mysql_query($import) or die(mysql_error());
}
fclose($handle);
print "Import done";
}
else
{
print "<form action='import.php' method='post'>";
print "Type file name to import:<br>";
print "<input type='text' name='filename' size='20'><br>";
print "<input type='submit' name='submit' value='submit'></form>";
}
?>