When i try to upload a tab delimted file I get this error:
Column count doesn't match value count at row 1
I can assure you that I have the nine fields in the dba and that there are nine fields in my text document. My thought is that is it occuring because of the way that I am trying to parse the file. Does anyone have a suggestion on how I should go about fixing this. I have included an attachment of the file that i am uploading and below is my code and layout of my dba.
Bib varchar(255) No Change Drop Primary Index Unique
FirstName varchar(255) No Change Drop Primary Index Unique
LastName varchar(255) No Change Drop Primary Index Unique
Addr varchar(255) No Change Drop Primary Index Unique
City varchar(255) No Change Drop Primary Index Unique
State varchar(255) No Change Drop Primary Index Unique
Zip varchar(255) No Change Drop Primary Index Unique
Email varchar(255) No Change Drop Primary Index Unique
TimeOfDay varchar(255) No Change Drop Primary Index Unique
<?php
if(isset($POST['upload']) && $FILES['userfile']['size'] > 0)
{
$fileName = $FILES['userfile']['name'];
$tmpName = $FILES['userfile']['tmp_name'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
for($i=0; $i<sizeof($fp); $i++)
{
$line = trim($fp[$i]);
$arr = explode("\t", $line);
#if your data is comma separated
# instead of tab separated,
# change the '\t' above to ','
$query = "INSERT INTO 2004Scores (Bib, FirstName, LastName, Addr, City, State, Zip, Email, TimeOfDay) ".
"VALUES ('". implode("','", $arr) ."')";
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
# first get a mysql connection as per the FAQ
$hostname_mydba = "localhost";
$database_mydba = "ResultsDB";
$username_mydba = "root";
$password_mydba = "passw";
$mydba = mysql_connect($hostname_mydba, $username_mydba, $password_mydba) or trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_mydba);
}
fclose($fp);
mysql_query($query) or die(mysql_error());
echo "<br>File $fileName uploaded<br>";
}
?>
<form method="post" enctype="multipart/form-data">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246">
<input type="hidden" name="MAX_FILE_SIZE" value="2000000">
<input name="userfile" type="file" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>