I have a script that gets data from a database, then loops through the results from the SELECT query by using a forloop and has a query that inserts the array data into another datbase. However only the first record gets inserted.
I get no errors
Here is the code.
//Get all from job
$getRecords = $connection->prepare("SELECT `CustomerFirstName`,`CustomerLastName`,`CASS_STD_LINE1`,`CASS_STD_LINE2`,`CASS_STD_CITY`,`CASS_STD_STATE`,`CASS_STD_ZIP`,`CustomerCounty`,`CustomerNumber`,`DealNumber`,`TradeIn_1_VIN`,`TradeIn_1_Make`,`TradeIn_1_Model`,`TradeIn_1_Year`,`FrontGross`,`BackGross`,`HoldBackAmount`,`VehicleYear`,`VehicleMake`,`VehicleModel`,`VehicleVIN`,`EntryDate`,`matched`,`notNew` FROM `auth` WHERE `matched` = ?");
$getRecords->execute(array($_POST['jobName']));
$gotRecords = $getRecords->fetchAll(PDO::FETCH_ASSOC);
$getRecords = null;
//Loop Through all records found with matching job name
for($i=0;$i<count($gotRecords); ++$i){
$rec = $remote->prepare("INSERT INTO `cob_matched_records`(first) VALUES (?)");
$rec->execute(array($gotRecords[$i]['CustomerFirstName']));
}
insert into select .. from .. where ..- and you've already got theselect .. from .. where ..part$gotRecords? You're selecting a lot of fields but onlyCustomerFirstNameis used "in" the INSERT statement. And what's this:$getRecords = null;before the loop? Can't imagine that the code inserts anything.$connection->.../$remote->...