/home/techb158/workloadmatch.com/Manager/Add_Course_Session.php (6931B)
⌠Invalid slot: Cannot find time range for selected Group_Slot_ID ($Group_Slot_ID).
"; //exit; } // 3. Now lookup Schedule_ID from course_group_schedule_main /*$stmt = $mysqli->prepare(" SELECT Schedule_ID, End_Date FROM course_group_schedule_main WHERE Program_ID = ? AND Course_ID = ? AND Group_ID = ? AND Time_Slot_ID = ? AND Time_Slot = ? AND Start_Time = ? AND End_Time = ? LIMIT 1");*/ $stmt = $mysqli->prepare(" SELECT Schedule_ID,Time_Slot_ID, End_Date FROM course_group_schedule_main WHERE Program_ID = ? AND Course_ID = ? AND Group_ID = ? AND Time_Slot = ? AND Start_Time = ? AND End_Time = ? LIMIT 1"); $stmt->bind_param( "iiisss", // <-- 7 type letters $Program_ID, // int $Course_ID, // int $Group_ID, // int //$Time_Slot_ID, // int << PROBLEM: This should be "i" but in your query you called it Time_Slot_ID $Time_Slot, // string $Start_Time, // string $End_Time // string ); /* error_log("bind_param vars: " . json_encode([ $Program_ID, $Course_ID, $Group_ID, $Group_Slot_ID, $Time_Slot, $Start_Time, $End_Time ])); */ if (!$stmt) { die("Prepare failed: " . $mysqli->error); } $stmt->execute(); $stmt->bind_result($Schedule_ID, $Time_Slot_ID, $Course_End_Date); $found = $stmt->fetch(); $stmt->close(); /* header('Location: addcoursesession.php?error='.$Program_ID .'"-"'.$Course_ID.'"-"'.$Group_ID.'"-"'.$Time_Slot_ID.'"-"'.$Schedule_ID.'"-"'.$Time_Slot .'"-"'.$End_Time .'"-"'.$Start_Time ); exit; header('Location: addcoursesession.php?error='. $Time_Slot .'"-"'.$End_Time .'"-"'.$Start_Time .'"-"'.$Program_ID .'"-"'.$Course_ID.'"-"'.$Group_ID.'"-"'.$Group_Slot_ID.'"-"'.$Schedule_ID.'"-"'.$found); exit; */ if (!$found || !$Schedule_ID) { set_flash_msg('⌠Schedule not found in main table. You must create the main course schedule first!', 'warning'); header('Location: addcoursesession.php'); //echo "⌠Schedule not found in main table. You must create the main course schedule first!
"; exit; } // 4. Check that session date is <= end date for the course if (strtotime($Session_Date) > strtotime($Course_End_Date)) { set_flash_msg('⌠Cannot add session after course end date ($Course_End_Date).'. $Course_End_Date, 'warning'); header('Location: addcoursesession.php'); //echo "⌠Cannot add session after course end date ($Course_End_Date).
"; //exit; } // 5. Check if the same session already exists $stmt = $mysqli->prepare("SELECT COUNT(*) FROM schedule_course_for_group WHERE Schedule_ID = ? AND Start_Date = ?"); $stmt->bind_param("is", $Schedule_ID, $Session_Date); $stmt->execute(); $stmt->bind_result($exists); $stmt->fetch(); $stmt->close(); /* header('Location: addcoursesession.php?error='. $Time_Slot .'"-"'.$End_Time .'"-"'.$Start_Time .'"-"'.$Program_ID .'"-"'.$Course_ID.'"-"'.$Group_ID.'"-"'.$Group_Slot_ID.'"-"'.$Course_Name.'"-"'.$Session_Date); exit; */ if ($exists > 0) { set_flash_msg('⌠Session already exists for this date!', 'warning'); header('Location: addcoursesession.php'); //echo "⌠Session already exists for this date!
"; //exit; } $nameStmt = $mysqli->prepare("SELECT Course_Name,Course_Time FROM Courses WHERE Course_ID = ?"); $nameStmt->bind_param("i", $Course_ID); $nameStmt->execute(); $nameStmt->bind_result($Course_Name,$Course_Hours ); $nameStmt->fetch(); $nameStmt->close(); if ($Course_Name === null) { die("⌠Invalid Course_ID ($Course_ID), no course found!"); } // 6. Insert the new session row $stmt = $mysqli->prepare("INSERT INTO schedule_course_for_group (Schedule_ID, Program_ID, Course_ID, Group_ID, Group_Slot_ID, Course_Hours, Course_Name, Reserve_Course, Time_Slot, Start_Date, End_Date, Start_Time, End_Time, Assigned, Last_Updated) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 0, NOW()) "); if (!$stmt) { set_flash_msg('repare failed: ' . $mysqli->error, 'warning'); header('Location: addcoursesession.php'); //echo "Prepare failed: " . $mysqli->error . "
"; //exit; } $stmt->bind_param( "iiiiiisisssss", $Schedule_ID, $Program_ID, $Course_ID, $Group_ID, $Time_Slot_ID, $Course_Hours, $Course_Name, $Reserve_Course, $Time_Slot, $Session_Date, $Session_Date, $Start_Time, $End_Time ); /* var_dump([ $Schedule_ID, $Program_ID, $Course_ID, $Group_ID, $Group_Slot_ID, $Course_Name, $Reserve_Course, $Time_Slot, $Session_Date, $Session_Date, $Start_Time, $End_Time ]); */ if (!$stmt) { die("Prepare failed: " . $mysqli->error); } if ($stmt->execute()) { set_flash_msg('✅ Session added successfully!', 'warning'); header('Location: addcoursesession.php'); //echo "✅ Session added successfully! Schedule_ID: $Schedule_ID
"; } else { set_flash_msg('Insert failed: ' . $stmt->error, 'warning'); header('Location: addcoursesession.php'); //echo "Insert failed: " . $stmt->error . "
"; } $stmt->close(); } ?>