?
Solved

Invalid Field Count

Posted on 2006-05-18
4
Medium Priority
?
8,323 Views
Last Modified: 2013-12-12
Hi,

I'm trying to import a CSV file into PhpMyAdmin and I keep getting this error

"Invalid field count in CSV input on line xxxx"

I managed to get rid of the error a couple of times by deleting the line it was referencing, but now it is stuck at one spot and no matter how many lines i delete i still get the error....

Here is a sample of the file that works:

-8.927,143.191,WESTERN,SOUTH FLY,ORIOMO-BITURI RURAL,ABAM
-8.285,143.151,WESTERN,SOUTH FLY,KIWAI RURAL,ABERAGEREMA
-8.057,142.875,WESTERN,MIDDLE FLY,GOGODALA RURAL,ADIBA
-6.217,142.484,WESTERN,MIDDLE FLY,NOMAD RURAL,ADUMARI

and here is a couple of lines i deleted because they seemingly had an invalid field count

-8.013,146.889,CENTRAL,GOILALA,GUARI RURAL,RUPILA
-8.234,147.353,NORTHERN,SOHE,KIRA RURAL,OIBO
-8.527,147.99,NORTHERN,SOHE,TAMATA RURAL,OITA TANDI
-4.107,142.68,EAST SEPIK,AMBUNTI/DREKIKIR,AMBUNTI RURAL,TONGAJAMB


These are the options I specified for Load CSV in phpmyadmin 2.8

Fields terminated by: ,
Fields enclosed by: " (they're not actually enclosed by anything...)
Fields escaped by: \
Lines terminated by: auto
Column names: lat,long,province,district,llg,ward

Database structure:

CREATE TABLE `temp_locations` (
  `temp_location_id` int(11) NOT NULL auto_increment,
  `lat` float NOT NULL default '0',
  `long` float NOT NULL default '0',
  `province` varchar(60) NOT NULL default '',
  `district` varchar(60) NOT NULL default '',
  `llg` varchar(60) NOT NULL default '',
  `ward` varchar(60) NOT NULL default '',
  PRIMARY KEY  (`temp_location_id`)
) TYPE=MyISAM AUTO_INCREMENT=1 ;

What am I doing wrong??

Thanks
Ant
0
Comment
Question by:antum
  • 2
4 Comments
 
LVL 16

Expert Comment

by:dr_dedo
ID: 16714096
i can't find any thing bizzar in that CSV, and i'm not that familiar with phpmyadmin, but i can give u that code which should get the job done!
<?
$con = mysql_connect("localhost","root","");
$con = mysql_select_db("test");
$handle = fopen('C:\csv.csv', "r");
while (($data = fgetcsv($handle)) !== FALSE)
{
if(!mysql_query("insert into `temp_locations` (`lat`,`long`,`province`,`district`,`llg`,`ward`) values({$data[0]},{$data[1]},'{$data[2]}','{$data[3]}','{$data[4]}','{$data[5]}')"))
echo mysql_error()." <b>";
}
echo "Done";
?>
0
 
LVL 40

Accepted Solution

by:
Richard Quadling earned 1500 total points
ID: 16715961
OOI. If you have some data in the table already, can you do a CSV EXPORT and compare the files to see what sort of differences exist.

Was the file generated with the same line termination characters?

If the csv file has been through different editors, it MAY have ended up with CR/LF and CR and LF line terminators. Maybe.
0
 
LVL 29

Expert Comment

by:fibo
ID: 16728833
For the problem-ful lines:
Could you try to re-submit them after enclosing each and every text data within double quotes " ... "?
0
 
LVL 40

Expert Comment

by:Richard Quadling
ID: 16884220
What was the problem?
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses
Course of the Month16 days, 13 hours left to enroll

862 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question