prepare(" INSERT INTO students (student_name, student_name_pb, father_name, father_name_pb, mother_name, mother_name_pb, roll_no, reg_no, date_of_birth, date_of_admission, season, class, school_centre, photo_path) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?) "); $stmt->bind_param( "ssssssssssssss", $student_name, $student_name_pb, $father_name, $father_name_pb, $mother_name, $mother_name_pb, $roll_no, $reg_no, $dob, $doa, $season, $class, $school_centre, $photo_path ); if ($stmt->execute()) { $_SESSION['success'] = "Student added successfully. Roll No: $roll_no"; } else { $_SESSION['error'] = "Error adding student: " . $conn->error; } header("Location: students.php"); exit; } /* ===================== DELETE STUDENT ===================== */ if (isset($_GET['delete'])) { $id = intval($_GET['delete']); // First get photo path to delete file $result = $conn->query("SELECT photo_path FROM students WHERE id = $id"); if ($row = $result->fetch_assoc()) { if (!empty($row['photo_path']) && file_exists($row['photo_path'])) { unlink($row['photo_path']); } } $conn->query("DELETE FROM students WHERE id = $id"); $_SESSION['success'] = "Student deleted successfully."; header("Location: students.php"); exit; } /* ===================== FETCH STUDENTS ===================== */ $students = $conn->query("SELECT * FROM students ORDER BY id DESC"); ?>