My code works to import the data into mysql, but the command line is giving me an error:

PHP Fatal error: Column 'country_code' cannot be null in /home/jharvard/vhosts/pset8/includes/functions.php on line 57

The table is populated in PHPMyAdmin and appears accurate. When I downloaded into a spreadsheet though I noticed a few lines listed as:

INSERT INTO places (id, country_code, postal_code, place_name, admin_name1, admin_code1, admin_name2, admin_code2, admin_name3, admin_code3, latitude, longitude, accuracy) VALUES

Not sure what I am doing wrong especially since the table seems to be populated correctly.

1 Answer 1


The table probably already has values in it or is getting some loaded in successfully, but the problem isn't with what is already in the table.

Basically, it looks like something is trying to do an insert with no values, or at least no value or a null value for the country_code column. Your example of the line insert into places(....) VALUES looks like it should be followed by 12 values, one for each field except ID (which I assume is being generated by the database itself). Assuming that the line isn't continued somewhere else, it looks like the needed values just aren't there.

Except for the ID field, all values will be taken from the insert command. Since the country_code column requires a value (it doesn't allow null), it is immediately erroring out. Either the data values are there and an explicit value of NULL is first in line (unlikely), or there simply aren't any values attached to the insert command after the keyword VALUES.

Check on what's happening at line 57 in functions.php Are the values getting appended correctly to the insert command?

If this answers your question, please mark your question as answered. Let's keep up on forum maintenance. ;-)

  • Thank you for your response. The strange thing is I've looked at the underlying txt file and I do not see any lines with a NULL or empty value for "country_code". There are over 4,000 lines in the file and only about 4 or 5 of the "INSERT INTO" lines appearing in the spreadsheet I download from PHPMyAdmin. The rest of the lines appear to match the txt file I was extracting perfectly. Commented May 10, 2015 at 0:49
  • That confirms part of what I said. Here's what it comes down to. That error says that there's a statement of the form INSERT INTO table ( ... column names...) VALUES with nothing after the keyword VALUES. There must be a value corresponding to each column. With no values, it will cause an error. What's causing this to happen? What code is failing to append the values?
    – Cliff B
    Commented May 10, 2015 at 1:28
  • I'm probably not articulating myself correctly. That's essentially what I'm asking. The code seems to be working properly and the PHP table is being generated correctly. There are a few anomalies if I download a separate spreadsheet, but I don't see anything in the underlying text file (e.g. no columns missing values) that could be causing this small amount of issues or the error. Commented May 10, 2015 at 17:02
  • I have experienced the exact same issue, the import of the US location file into mySQL seems to be totally fine, but twice (out of thousands of iterations) the command line prints 'fatal error'. It is quite odd. Have you figured out what was wrong Tarek? Commented Oct 31, 2015 at 15:02
  • Anyone was able to figure it out? I am having exactly the same problem =/ Commented Nov 24, 2015 at 21:56

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .