0

I've gotten import.php working - enough to print out the values in US.txt correctly in arrays onto the screen.

I'm using the below code to try and insert into database:

        if(is_readable($filename))
    {
        $geo = fopen("/home/jharvard/vhosts/pset8/bin/US.txt","r");
        while (($lines = fgetcsv($geo, 512, "\t")) !== FALSE)
        {
            query("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(?,?,?,?,?,?,?,?,?,?,?,?,?)",$lines[0],$lines[1],$lines[2],$lines[3],$lines[4],$lines[5],$lines[6],$lines[7],$lines[8],$lines[9],$lines[10],$lines[11],$lines[12]);
        }
        fclose($geo);
        print("Done!");            
    }

but nothing is inserting and I get the following error code.

jharvard@appliance (~/vhosts/pset8/bin): ./import /home/jharvard/vhosts/pset8/bin/US.txt PHP Notice: Undefined offset: 12 in /home/jharvard/vhosts/pset8/bin/import on line 33 PHP Stack trace: PHP 1. {main}() /home/jharvard/vhosts/pset8/bin/import:0

Notice: Undefined offset: 12 in /home/jharvard/vhosts/pset8/bin/import on line 33

Call Stack: 0.0001 124876 1. {main}() /home/jharvard/vhosts/pset8/bin/import:0

PHP Fatal error: Column 'accuracy' cannot be null in /home/jharvard/vhosts/pset8/includes/functions.php on line 57 PHP Stack trace: PHP 1. {main}() /home/jharvard/vhosts/pset8/bin/import:0 PHP 2. query() /home/jharvard/vhosts/pset8/bin/import:33 PHP 3. trigger_error() /home/jharvard/vhosts/pset8/includes/functions.php:57

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

Call Stack: 0.0001 124876 1. {main}() /home/jharvard/vhosts/pset8/bin/import:0 0.0007 142436 2. query() /home/jharvard/vhosts/pset8/bin/import:33 0.0033 147804 3. trigger_error() /home/jharvard/vhosts/pset8/includes/functions.php:57

I've tried query in a few diffent ways but I can't understand why it won't work.

Thanks

  • 1
    $lines[12] doesn't exist on $lines as return value from fgetcsv...get rid of "id" as one of your insert values – Mauricio Aguilar Cardenas Nov 16 '15 at 20:29
  • Thanks, this has worked. Data seems to stop inputting after the 30th insert. How do you up the limit from 30 in phpMyAdmin? – Kris Valentine Nov 16 '15 at 20:44
  • 1
    Are you sure it's stopping at 30? 30 happens to be the default number of rows that phpmyadmin displays at any given time. You'd have to page through the data, or you could run the following query on the SQL tab: ` SELECT count(*) from places` to determine how many rows exist in the table. (I think it's also displayed on the screen somewhere.) – Cliff B Nov 16 '15 at 20:47
  • Yes you're correct - I was being an idiot - please come take my computer off of me! Thanks Cliff – Kris Valentine Nov 16 '15 at 20:48
1

$lines[12] doesn't exist on $lines as return value from fgetcsv...get rid of "id" as one of your insert values – Mauricio Aguilar Cardenas 7 hours ago

Thanks, this has worked. Data seems to stop inputting after the 30th insert. How do you up the limit from 30 in phpMyAdmin? – Kris Valentine 7 hours ago

Are you sure it's stopping at 30? 30 happens to be the default number of rows that phpmyadmin displays at any given time. You'd have to page through the data, or you could run the following query on the SQL tab: SELECT count(*) from places to determine how many rows exist in the table. (I think it's also displayed on the screen somewhere.) – Cliff B 7 hours ago

Yes you're correct - I was being an idiot - please come take my computer off of me! Thanks Cliff – Kris Valentine 7 hours ago

asked and answered. Please click on the check to accept and remove from the question pool.

| improve this answer | |

You must log in to answer this question.

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