prepare("SELECT id, userrole, username FROM app_users WHERE username = ?"); $queryprm->bind_param("s", $username); $queryprm->execute(); $queryprmres = $queryprm->get_result()->fetch_assoc(); $cruserrole = $queryprmres["userrole"]; $cruserid = $queryprmres["id"]; if ($cruserrole == 'admin' || $cruserrole == 'superadmin') { $queryingr = $mysqli->prepare("INSERT INTO groups (userid, group_name) VALUES (?, ?)"); $queryingr->bind_param("is", $cruserid, $usergroup); if ($queryingr->execute()) { $messagetosend = 'success'; } else { $messagetosend = 'An error occurred while attempting to save the group to the database!'; } } else { $messagetosend = 'Only Admins and Superadmins can create new groups.'; } $response = array('result' => $messagetosend); echo json_encode($response); } else { header("Location: ../login.php"); } ?>