I am getting these errors in the loop in running import from the command line and cant figure out why I am getting this and how to get rid of it
PHP Notice: Undefined offset: 1 in /home/ubuntu/workspace/pset8/bin/import on line 31
Notice: Undefined offset: 1 in /home/ubuntu/workspace/pset8/bin/import on line 31 PHP Notice: Undefined offset: 2 in /home/ubuntu/workspace/pset8/bin/import on line 32
Notice: Undefined offset: 2 in /home/ubuntu/workspace/pset8/bin/import on line 32 PHP Notice: Undefined offset: 3 in /home/ubuntu/workspace/pset8/bin/import on line 33
Notice: Undefined offset: 3 in /home/ubuntu/workspace/pset8/bin/import on line 33 PHP Notice: Undefined offset: 4 in /home/ubuntu/workspace/pset8/bin/import on line 34
Notice: Undefined offset: 4 in /home/ubuntu/workspace/pset8/bin/import on line 34 PHP Notice: Undefined offset: 5 in /home/ubuntu/workspace/pset8/bin/import on line 35
Notice: Undefined offset: 5 in /home/ubuntu/workspace/pset8/bin/import on line 35 PHP Notice: Undefined offset: 6 in /home/ubuntu/workspace/pset8/bin/import on line 36
Notice: Undefined offset: 6 in /home/ubuntu/workspace/pset8/bin/import on line 36 PHP Notice: Undefined offset: 7 in /home/ubuntu/workspace/pset8/bin/import on line 37
Notice: Undefined offset: 7 in /home/ubuntu/workspace/pset8/bin/import on line 37 PHP Notice: Undefined offset: 8 in /home/ubuntu/workspace/pset8/bin/import on line 38
Notice: Undefined offset: 8 in /home/ubuntu/workspace/pset8/bin/import on line 38 PHP Notice: Undefined offset: 9 in /home/ubuntu/workspace/pset8/bin/import on line 39
Notice: Undefined offset: 9 in /home/ubuntu/workspace/pset8/bin/import on line 39 PHP Notice: Undefined offset: 10 in /home/ubuntu/workspace/pset8/bin/import on line 40
Notice: Undefined offset: 10 in /home/ubuntu/workspace/pset8/bin/import on line 40 PHP Notice: Undefined offset: 11 in /home/ubuntu/workspace/pset8/bin/import on line 41
Notice: Undefined offset: 11 in /home/ubuntu/workspace/pset8/bin/import on line 41
The code for my import file is
<?php
// TODO
// including the file thats has the query function
require("../includes/config.php");
//ensuring proper usage
if($argc != 2)
{
print("Usage : ./import path/to/file \n");
exit(1);
}
// if the file is there and can be read
if(is_readable($argv[1]))
{
$file = $argv[1];
//open file
$handle = fopen($file, "r");
if ($handle == false)
{
print("Could not open file./n");
exit(1);
}
// iterate over all the rows
while($row = fgetcsv($handle, "\t"))
{
$countrycode = $row[0];
$postalcode = $row[1];
$placename = $row[2];
$adminname1 = $row[3];
$admincode1 = $row[4];
$adminname2 = $row[5];
$admincode2 = $row[6];
$adminname3 = $row[7];
$admincode3 = $row[8];
$latitude = $row[9];
$longitude = $row[10];
$accuracy = $row[11];
//query to insert into db
CS50::query ("INSERT INTO places (country_code, postal_code, place_name, admin_name1, admin_code1,
admin_name2, admin_code2, admin_name3, admin_code3, latitude,
longitude, accuracy) VALUES (?,?,?,?,?,?,?,?,?,?,?,?)",$countrycode, $postalcode, $placename,
$adminname1, $admincode1, $adminname2, $admincode2, $adminname3,
$admincode3, $latitude, $longitude, $accuracy);
}
}
else
{
print("could not open/read file");
}
fclose($handle);
?>