I've got two queries which are, in the end, nearly exactly the same. But for some reason the first one works flawlessly and the second one doesn't add anything to the database nor gives back any error.
The one that works looks like this:
public function insertPits($pitstop, $RaceID, $managerId, $seasonNumber, $raceNumber) {
$sqlpit = "insert into pitstop (RaceID,managerid,season,race,PitStopNo,LapNo, Reason,TyreWear,FuelLeft,FuelLoad,PitTime) values ";
foreach ($pitstop as $pitstop){
$sqlpit .= "($RaceID,$managerId,$seasonNumber,$raceNumber,$pitstop[0],$pitstop[1],'$pitstop[2]',$pitstop[3],$pitstop[4],$pitstop[5],$pitstop[6]),";
}
$sqlpit =rtrim($sqlpit,",");
mysqli_query($GLOBALS["___mysqli_ston"], $sqlpit);
}
The one not working as it should:
public function insertStints($stints, $RaceID, $managerId, $seasonNumber, $raceNumber) {
$sqlstint = "insert into stint (RaceID,managerid,season,race,StintNo,Tyre) values ";
foreach ($stints as $stints) {
$sqlstint .= "($RaceID,$managerId,$seasonNumber,$raceNumber,$stints[0],$stints[7]),";
}
$sqlstint =rtrim($sqlstint,",");
mysqli_query($GLOBALS["___mysqli_ston"], $sqlstint);
}
$pitstop and $stints are both the exact same array, just different names. The pitstop database is filled correctly, the stints database stays empty without error.
The $sqlstint shows this as echo, which is right.. but it doesn't add anything:
insert into stint (RaceID,managerid,season,race,StintNo,Tyre)
values (40978,65,60,3,1,Extra Soft),
(40978,65,60,3,2,Extra Soft),
(40978,65,60,3,3,Extra Soft)
Does anyone have a clue how to fix this, or how to do it differently (maybe combine them into one function.. but to be honest.. I have no clue how to do that either). Hoping for your feedback!