As most peope seeking advise I’m a total newb so I’d appreciate some advise. I’m also old so you might have to speak up and repeat it a few times before it sinks in.
I have two strings coming out of a Flash app with pipe seperated values. I want to take these and polulate two columns in a mySQL DB
As a test, I managed to to insert using ‘explode’ and a foreach loop. This worked beautifully and here’s the code
$bmIDs = explode ('|', $_POST['userIDs']);
$sqlQuery = "INSERT INTO bm (bmUserID, bmID) VALUE (?,?)";
$stmt = $con->prepare($sqlQuery);
$stmt->bind_param("si", $userID,$bmID);
foreach ($bmIDs as $bmID){
$stmt->execute();
}
$stmt->close();
My problems started when I tried various methods to insert both exploded strings. I understand from reading on the web that it can’t be done with a foreach so I tried various things and ended up with a for loop. It echos a treat but will not insert into the DB. There are no entries in the PHP error log so I’m really stuck. Here’s my problem code:
$bms = explode('|', $_POST['users']);
$bmIDs = explode ('|', $_POST['userIDs']);
$sqlQuery = "INSERT INTO bm (bmUserID, bmID,bmName) VALUE (?,?,?)";
$stmt = $con->prepare($sqlQuery);
$stmt->bind_param("sss", $userID,$bmID,$bmName);
for($i = 0; $i < count($bmIDs); $i++) {
$bmID = $bmIDs[$i];
$bmName = $bms[$i];
$stmt->execute();
Help would be appreciated