0) { $message = 'Student ID already exists. Please use a different Student ID.'; $message_type = 'danger'; } mysqli_stmt_close($stmt); } // If no errors, insert student if (empty($message)) { // Generate QR code $qr_code = 'STU_' . $student_id . '_' . uniqid(); $sql = "INSERT INTO students ( student_id, qr_code, full_name, gender_id, year_level, course_id, department_id, school_id, birth_date, contact_number, email, address, created_at, updated_at, status ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, NOW(), NOW(), 1)"; $stmt = mysqli_prepare($conn, $sql); if ($stmt) { // Escape data $student_id = mysqli_real_escape_string($conn, $student_id); $full_name = mysqli_real_escape_string($conn, $full_name); $contact_number = mysqli_real_escape_string($conn, $contact_number); $email = mysqli_real_escape_string($conn, $email); $address = mysqli_real_escape_string($conn, $address); // Bind parameters based on birth_date if ($birth_date === NULL) { mysqli_stmt_bind_param($stmt, 'sssiiiiissss', $student_id, $qr_code, $full_name, $gender_id, $year_level, $course_id, $department_id, $school_id, null, $contact_number, $email, $address ); } else { mysqli_stmt_bind_param($stmt, 'sssiiiiissss', $student_id, $qr_code, $full_name, $gender_id, $year_level, $course_id, $department_id, $school_id, $birth_date, $contact_number, $email, $address ); } if (mysqli_stmt_execute($stmt)) { $new_student_id = mysqli_insert_id($conn); // Redirect to view the newly added student $_SESSION['flash_message'] = 'Student added successfully!'; $_SESSION['flash_type'] = 'success'; header("Location: view_student.php?id=$new_student_id"); exit(); } else { $message = 'Error adding student: ' . mysqli_error($conn); $message_type = 'danger'; } mysqli_stmt_close($stmt); } else { $message = 'Error preparing statement: ' . mysqli_error($conn); $message_type = 'danger'; } } } } include '../includes/header.php'; ?>

Add New Student

Back to Students
Student Information
Unique student identification number
Format: 0912-345-6789 or 09123456789
Cancel
Guidelines
  • Fields marked with * are required
  • Student ID must be unique
  • Birth date cannot be in the future
  • Email must be valid format (optional)
  • Contact number should include area code
  • QR code will be automatically generated
$(document).ready(function() { // Simple form submission $("#addStudentForm").submit(function(e) { // Simple validation - just check if required fields are filled let valid = true; // Check required fields const requiredFields = [ "student_id", "full_name", "gender_id", "year_level", "school_id", "department_id", "course_id" ]; requiredFields.forEach(field => { const element = $("[name=\'" + field + "\']"); const value = element.val().trim(); if (!value || value === "" || value === "0") { valid = false; element.addClass("is-invalid"); element.after(\'
This field is required.
\'); } else { element.removeClass("is-invalid"); element.next(".invalid-feedback").remove(); } }); if (!valid) { e.preventDefault(); alert("Please fill in all required fields marked with *"); return false; } // Show loading state $(this).find("button[type=\'submit\']").prop("disabled", true).html(\' Saving...\'); return true; }); // Remove error classes on input $("input, select, textarea").on("input change", function() { $(this).removeClass("is-invalid"); $(this).next(".invalid-feedback").remove(); }); // Auto-focus first field $("input[name=\'student_id\']").focus(); }); '; include '../includes/footer.php'; ?>