function joinSchool($mysqli, $userId, $schoolId) { if (doesUserExist($mysqli, $userId)) { if (doesSchoolExist($mysqli, $schoolId)) { if (!isUserInSchool($mysqli, $userId, $schoolId)) { if ($stmt = $mysqli->prepare("INSERT INTO members_schools SET member_id = ?, school_id = ?")) { $stmt->bind_param("ii", $userId, $schoolId); $stmt->execute(); return true; } else { return "Faulty MYSQL Statement"; } } else { return "User is already in school"; } } else { return "School does not exist"; } } else { return "User does not exist"; } }
?> <li><a href="group.php?id=<?php echo $group["id"]; ?> "><?php echo $group["name"]; ?> </a></li> <?php } ?> </ul> <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#group_popup">Create Group</button> <?php if (!isUserInSchool($mysqli, $_SESSION['user_id'], $id)) { ?> <button id="join_school" onclick="joinSchool(<?php echo $id; ?> );">Join School</button> <?php } else { ?> <button id="leave_school" onclick="leaveSchool(<?php echo $id; ?> );">Leave School</button> <?php }