Current location: Hot Scripts Forums » Programming Languages » PHP » error issue need help


error issue need help

Reply
  #1 (permalink)  
Old 02-28-05, 12:30 PM
natman natman is offline
New Member
 
Join Date: Jan 2005
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
error issue need help

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>
Attached Files
File Type: txt OzarkDB4.txt (11.9 KB, 2925 views)
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 05:34 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.