function save_class() { //add message to alert array include "../app/student/studentmanager.php"; $connection = db_connect(); //connect to database $class = $_SESSION['class']; $teacherid = $_SESSION['id']; $classname = $class['name'][0]; $query = "INSERT INTO `project`.`class` (`id`, `teacher_id`, `class_group`) VALUES (NULL, '{$teacherid}', '{$classname}')"; $result = mysqli_query($connection, $query); //perform query $classid = mysqli_insert_id($connection); if ($result) { //check if query ran for ($i = 0; $i < count($class['fname']); $i++) { create_student($class['fname'][$i], $class['lname'][$i], $classid); } add_success("Class Created."); clear_class(); } else { add_error("Class not created, Error in SQL"); } db_close($connection); }
if ($all_required_variables) { add_classstudent($fname, $lname); add_success("Student Added " . $fname . " " . $lname); header('location: classcreate.php'); die; } else { add_error("student error"); header('location: classcreate.php'); die; } } if (isset($_POST['classsave'])) { save_class(); header('location: classcreate.php'); die; } if (isset($_POST['classremove'])) { if (isset($_POST['removeid']) && trim($_POST['removeid']) !== '') { //if class name is set and not empty remove_student(trim($_POST["removeid"])); add_success("Student Removed"); header('location: classcreate.php'); die; } } if (isset($_POST['classclear'])) { clear_class(); add_success("Class Cleared"); header('location: classcreate.php'); die; }