Can you restructure it to use a single array? A single array would make more sense for this as with two arrays what do you do when the city array has 7 elements and the state array has only 4. With a single array with an object in each element containing both the city and the state you only have one array to process through the loop and you guarantee that there are as many cities as there are states.
But it seems to not put any records into the table, just the error
INSERT INTO territories (city,state) VALUES (San Diego,CA)Invalid query: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘Diego,CA)’ at line 1
As you can see from the error message there are no quotes around either Diego or CA. Both strings need to be within quotes for the query to work.
Note also that the mysql calls you are using are not supported in PHP 7 so you will need to replace them with either mysqli or PDO equivalents before your PHP version gets upgraded to the next version (which is apparently scheduled for release in November).
ok, thanks for letting me know
changed the loop to
foreach($territory as $key => $value) {
$qry = "INSERT INTO territories (city,state) VALUES ('".$key."','".$value."')";
$sth = $dbh->query($qry);
}
It worked like a champ!
I also have a junction table (provider_territory) and am trying to figure out how to get the id (PK) inserter in the territories table, something like
INSERT INTO provider_territory (provider_id,territory_id) VALUES ('THE PK FROM THE providers TABLE,THE PK FROM the territories TABLE we just inserted into)