<?php
include '../connectdb.php';
$sqlNAME = 'INSERT INTO group_general (group_name)
VALUES (?)';
if($statementNAME = $connect->prepare($sqlNAME)) {
$statementNAME->bind_param(
"s",
$_POST['groupName']
);
/* Insert group name into DB */
if ($statementNAME->execute()) {
echo "Success";
}
else {
echo "Failed";
}
}
$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();
}
/* For each user selected and put in the array, insert them into the DB combined with the ID of the group */
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.'")';
}
?>
I don't understand what I did wrong. At the end it says "Array to string conversion in ...", while I am inserting one value of an array into the DB. Can you please help me?