Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $fmcourse = $_POST['fm_courses'];
- $student_id = $_POST["id"];
- $batch_id = $_POST["name"];
- delete_enrollments( $student_id, $batch_id );
- foreach($fmcourse as $fmc) {
- $course_id = $fmc;
- if( record_exists( $student_id, $course_id, $batch_id ) == FALSE ) {
- $stmt = mysqli_prepare($conn, "INSERT INTO enrollments (enrollment_id, student_id, course_id, batch_id, is_deleted, joining_date) VALUES( NULL, ?, ?, ?, 0, NOW() );");
- $is_binded = mysqli_stmt_bind_param($stmt, "iii", $student_id, $course_id, $batch_id);
- $is_exec = mysqli_stmt_execute($stmt);
- mysqli_stmt_close($stmt);
- }
- else {
- undelete_enrollment($student_id, $course_id, $batch_id);
- }
- }
- function undelete_enrollment($student_id, $course_id, $batch_id) {
- global $conn;
- $stmt = mysqli_prepare($conn, "UPDATE enrollments SET is_deleted = 0, joining_date = NOW() WHERE student_id= ? AND course_id = ? AND batch_id = ?");
- $is_binded = mysqli_stmt_bind_param($stmt, "iii", $student_id, $course_id,$batch_id);
- $is_exec = mysqli_stmt_execute($stmt);
- mysqli_stmt_close($stmt);
- return $is_exec;
- }
- function record_exists( $student_id, $course_id, $batch_id ) {
- global $conn;
- $stmt = mysqli_prepare($conn, "SELECT COUNT(enrollment_id) as total FROM enrollments WHERE student_id= ? AND course_id = ? AND batch_id = ?");
- $is_binded = mysqli_stmt_bind_param($stmt, "iii", $student_id, $course_id, $batch_id);
- $is_exec = mysqli_stmt_execute($stmt);
- $result = mysqli_stmt_get_result($stmt);
- $record = mysqli_fetch_assoc($result);
- mysqli_stmt_close($stmt);
- return ( isset( $record['total'] ) AND $record['total'] > 0 );
- }
- function delete_enrollments( $student_id, $batch_id ) {
- global $conn;
- $stmt = mysqli_prepare($conn, "UPDATE enrollments SET is_deleted = 1 WHERE student_id = ? AND batch_id =?;");
- $is_binded = mysqli_stmt_bind_param($stmt, "ii", $student_id, $batch_id);
- $is_exec = mysqli_stmt_execute($stmt);
- mysqli_stmt_close($stmt);
- return $is_exec;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement