<?php
include '../connectdb.php';
$sqlNAME = 'INSERT INTO group_general (group_name)
VALUES (?)';
if($statementNAME = $connect->prepare($sqlNAME)) {
$statementNAME->bind_param(
"s",
$_POST['groupName']
);
$statementNAME->execute();
}
$groupName = $_POST['groupName'];
$selectGROUPID = 'SELECT * FROM group_general WHERE group_name = "'.$groupName.'"';
$resultGROUPID = $connect->query($selectGROUPID);
if ($resultGROUPID->num_rows > 0) {
$rowGROUPID = $resultGROUPID->fetch_assoc();
}
/* The error is somewhere around here~ish */
for ($x=0; $x<sizeof($_POST['addedUsers']); $x++) {
$rowUSERS[$x] = $_POST['addedUsers'][$x];
$sqlUSERS = 'INSERT INTO group_users (user_name, group_id)
VALUES ("'.$rowUSERS[$x].'", "'.$rowGROUPID['group_id'].'")';
if($statementUSERS = $connect->prepare($sqlUSERS)) {
if ($statementUSERS->execute()) {
echo "Successfully created the group!";
}
else {
echo "Failed to create the group...";
}
}
}
?>
So my issue is whenever a user selects multiple people (so the array $rowUSERS[] becomes more than only the 0 value), it only inserts the first selected user into the DB while it actually should loop through every selected user and insert it one by one. I really don't know what I did wrong here. Can you please look at it and help me?