Invalid Field Count

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
antumAsked:
Who is Participating?
 
Richard QuadlingSenior Software DeveloperCommented:
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
 
dr_dedoCommented:
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
 
Bernard S.CTOCommented:
For the problem-ful lines:
Could you try to re-submit them after enclosing each and every text data within double quotes " ... "?
0
 
Richard QuadlingSenior Software DeveloperCommented:
What was the problem?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.