18/07/2009
Technical Stuffs

Invalid field count in csv input on line 1

When importing CSV data into my MySQL database using PHPMyAdmin, I found following error: Invalid field count in csv input on line 1.

It’s odd since I’ve manually count field numbers and compared with column on my CSV files, they’re exactly match.

Then I found something strange. PHPMyAdmin is automatically use semicolon ( ; ) as field delimiter instead of comma ( , ). Quick fix for this problem is to change the delimiter symbol manually.

phpMyAdmin screenshot

In the picture above, I replaced semicolon (rounded with blue circle) with comma and everything is alright.

38 thoughts on “Invalid field count in csv input on line 1
  1. Thanks! This really helped alot. Spent a good while trying to find problem, and its something as small as this.

    Thanks again

  2. you’ve got no idea how much you just helped me out right here!

    Thanks a million!

  3. Thank you, thank you, thank you!

    I’d been pulling out my hair for two hours until I stumbled upon your site.

    Comma vs. semicolon… phew – I didn’t spot that. Amazing what grief one pixel’s difference can cause.

    phpMyAdmin can go stuff its semicolon right up its last two syllables of the aforementioned punctuation mark.

    Terima kasih banyak

  4. Thank you. I have been looking all day on the web trying to get an answer. My upload worked fine.

    Cheers,

    Alan

  5. Wow to think PHP used to not do this and does now.

    This is stupid and the sheer number of posts i have seen of users with this problem i can’t believe they did soemthing so stupid just to maintain the old excel standard, clearly CSV stands for COMMA separated value.

  6. In my CSV file the fields were surrounded by ” (double quotes).
    Please be sure there are no double quotes INSIDE THE FIELDS. Open your CSV file in Excel or scalc (openoffice suite):
    – In scalc go to Edit > Find /Replace
    – In Excel follow this steps: http://support.microsoft.com/kb/288291

    Replace all the ” (double quotes) with ‘ (single quotes).

    Another problem was with the DATETIME fields in MYSQL. In scalc select them all and right-click on them > Format Cells > and put “JJ-MM-DD UU:MM:SS” in the Format code box.

    I’m only allowed to have in MYSQL first the year, then the month and then the day. For example “2009-12-29”.

    After following these steps it worked for me.

    And BTW, if there are still problems, open your CSV with Notepad or another text editor and check if every line has the right count of fields.

  7. Hi,

    its relay Great!

    its helped me alot.

    really Thanks….
    Thanks….
    Thanks….
    Thanks….
    Thanks….
    Thanks….

    vivek
    CHPL pune

  8. i have same problem but still unable to solve it as per your above instructions

  9. I have funded best solution

    First of all open CSV file in Microsoft Excel and save it again with new name then

    To solve this I had to do the following:

    Import
    Browse for your csv file.
    Select CSV using LOAD DATA (rather than just CSV)
    Change โ€œFields terminated byโ€ from โ€œ;โ€ to โ€œ,โ€
    Make sure โ€œUse LOCAL keywordโ€ is selected.
    Click โ€œGoโ€

  10. The above problem is probably due to the Windows default setting in Regional Settings (Control Panel) for the CSV file separator. It seems the USA and UK use different default values.

  11. Another useful trick, when you’re having problems importing an Access table, is to open up the file in TextPad (or some other editor) and examine your data. You’ll probably find many errors. For instance if you have ” in your text field you’ll have to change it something else. I find that Access search and replace can be a little tempermental, so simply telling Access to replace the ” with a ^ doesn’t always work as expected.

  12. Great job, I got this when trying to upload a csv database after editing it, I thought I broke it lol.

    Thanks!

  13. I’ve tried everything you said but only the first row out of 142 rows gets inserted. I also have this issue. I have 8 columns A thru H.
    In the DB the first field is Product_ID and its set to auto increment. Even only after only one row being inserted the data in the CSV file does not transfer over to the same DB fields as they should (out of sync). Very frustrated.

  14. Thanks! I also had trouble with uploading a CSV created in Excel, but removing quotation mark in ‘Fields enclosed by’ field I was able to fix it.

    Thanks again!

  15. VERY helpful thanks. I kept getting errors! This worked perfectly.

    Thanks again,
    Mike

  16. oh .. thank you so much ^^” .. i try to solve this problem by myself very long time

Leave a Reply