hjkhhndndndnd,trt
bnmbertsu,yu,yu,fffffffy,ltdfg
/
home4
/
gofvotmy
/
public_html
/
shs_admission
/
Upload FileeE
HOME
<?php session_start(); include 'connection.php'; error_reporting(E_ALL); if (isset($_POST['Submit'])) { // Collect form data // header("Location:payment.php"); // Define the SQL query with placeholders $insert = "INSERT INTO shs_registration (Student_Name, DOB, Student_Photo, Religion, Nationality, Category, Category_Cert, Address, Parent_Email, Mother_Name, Mother_Qual, Mother_Prof, is_mother_ex_student, Mother_Pass, is_mother_govt_employee, mother_sector, Father_Name, Father_Qual, Father_Prof, is_father_govt_employee, father_sector, Tel, Whatsapp, Distance_From_School, Medical_Cond, Name_Address_Pre_School, Sibbling_Studying, Sibbling_Name_Class, Latest_Report_Card, DOB_Cert, Parents_Adhaar) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"; // Create a prepared statement $stmt = mysqli_prepare($con, $insert); if ($stmt) { // Handle image file upload if ($_FILES['student_photo']['error'] === UPLOAD_ERR_OK) { $tempFilePath = $_FILES['student_photo']['tmp_name']; $fileName = $_FILES['student_photo']['name']; $uploadDir = 'uploads/images/'; // Define the first directory path $adminUploadDir = 'admin/uploads/images/'; // Define the second directory path $uploadFilePath = $uploadDir . $fileName; $adminUploadFilePath = $adminUploadDir . $fileName; // Ensure the directories exist; create them if they don't if (!file_exists($uploadDir)) { mkdir($uploadDir, 0777, true); } if (!file_exists($adminUploadDir)) { mkdir($adminUploadDir, 0777, true); } // Copy the uploaded file to both directories if (copy($tempFilePath, $uploadFilePath) && copy($tempFilePath, $adminUploadFilePath)) { // Both files are successfully copied $studentPhoto = $uploadFilePath; } else { echo "Error uploading student photo."; exit; // Terminate the script if there's an error } } else { echo "Error: " . $_FILES['student_photo']['error']; exit; } if ($_FILES['pdf_report_card']['error'] === UPLOAD_ERR_OK) { $uploadDirPrimary = 'uploads/report_card/'; // Define the primary directory $uploadDirAdmin = 'admin/uploads/report_card/'; // Define the admin directory $uploadFilePrimary = $uploadDirPrimary . basename($_FILES['pdf_report_card']['name']); $uploadFileAdmin = $uploadDirAdmin . basename($_FILES['pdf_report_card']['name']); if (move_uploaded_file($_FILES['pdf_report_card']['tmp_name'], $uploadFilePrimary)) { // Set the PDF file path for the primary directory $latestReportCard = $uploadFilePrimary; // Copy the file to the admin directory if (copy($uploadFilePrimary, $uploadFileAdmin)) { // File copied successfully } else { echo "Error copying PDF report card file to the admin directory."; } } else { echo "Error uploading PDF report card."; exit; // Terminate the script if there's an error } } else { // Handle the case when no PDF Report Card file is uploaded $latestReportCard = null; // Set to NULL if no PDF Report Card is provided } // Handle DOBCert file upload if ($_FILES['dob_cert']['error'] === UPLOAD_ERR_OK) { $uploadDir = 'uploads/dob_certs/'; // Define the directory where you want to store DOBCert files $uploadDirAdmin = 'admin/uploads/dob_certs/'; // Define the admin directory for DOBCert $uploadFile = $uploadDir . basename($_FILES['dob_cert']['name']); $uploadFileAdmin = $uploadDirAdmin . basename($_FILES['dob_cert']['name']); if (move_uploaded_file($_FILES['dob_cert']['tmp_name'], $uploadFile)) { // Set the DOBCert file path $DOBCert = $uploadFile; // Copy the file to the admin directory if (copy($uploadFile, $uploadFileAdmin)) { // File copied successfully } else { echo "Error copying DOB Certificate to the admin directory."; } } else { echo "Error uploading DOB Certificate."; exit; // Terminate the script if there's an error } } else { // Handle the case when no DOB Certificate is uploaded $DOBCert = null; // Set to NULL if no DOB Certificate is provided } // Handle parentsAdhaar file upload // if ($_FILES['aadhaar']['error'] === UPLOAD_ERR_OK) { // $uploadDir = 'uploads/aadhaar/'; // $uploadFile = $uploadDir . basename($_FILES['aadhaar']['name']); // if (move_uploaded_file($_FILES['aadhaar']['tmp_name'], $uploadFile)) { // $parentsAdhaar = $uploadFile; // } else { // echo "Error uploading parentsAdhaar."; // exit; // } // } else { // echo "Error: " . $_FILES['aadhaar']['error']; // exit; // } if ($_FILES['aadhaar']['error'] === UPLOAD_ERR_OK) { $uploadDir = 'uploads/aadhaar/'; // Define the directory where you want to store Aadhaar files $uploadDirAdmin = 'admin/uploads/aadhaar/'; // Define the second directory for admin $uploadFile = $uploadDir . basename($_FILES['aadhaar']['name']); $uploadFileAdmin = $uploadDirAdmin . basename($_FILES['aadhaar']['name']); if (move_uploaded_file($_FILES['aadhaar']['tmp_name'], $uploadFile)) { // Set the Aadhaar file path $parentsAdhaar = $uploadFile; // Copy the file to the admin directory if (copy($uploadFile, $uploadFileAdmin)) { // File copied successfully } else { echo "Error copying Aadhaar file to the admin directory."; } } else { echo "Error uploading Aadhaar file."; exit; // Terminate the script if there's an error } } else { echo "Error: " . $_FILES['aadhaar']['error']; exit; // Terminate the script if there's an error } // if ($_POST['category'] === 'General') { // $categoryCert = null; // } else { // if ($_FILES['cat_cert']['error'] === UPLOAD_ERR_OK) { // $uploadDir = 'uploads/cat_cert/'; // Define the directory where you want to store Category Certificate PDFs // $uploadFile = $uploadDir . basename($_FILES['cat_cert']['name']); // if (move_uploaded_file($_FILES['cat_cert']['tmp_name'], $uploadFile)) { // // Set the Category Certificate PDF file path // $categoryCert = $uploadFile; // } else { // echo "Error uploading Category Certificate."; // exit; // Terminate the script if there's an error // } // } else { // echo "Error: " . $_FILES['cat_cert']['error']; // exit; // Terminate the script if there's an error // } // } if ($_POST['category'] === 'General') { $categoryCert = null; // Set to NULL if 'General' is selected } else { if ($_FILES['cat_cert']['error'] === UPLOAD_ERR_OK) { $uploadDirPrimary = 'uploads/cat_cert/'; // Define the primary directory $uploadDirAdmin = 'admin/uploads/cat_cert/'; // Define the admin directory $uploadFilePrimary = $uploadDirPrimary . basename($_FILES['cat_cert']['name']); $uploadFileAdmin = $uploadDirAdmin . basename($_FILES['cat_cert']['name']); if (move_uploaded_file($_FILES['cat_cert']['tmp_name'], $uploadFilePrimary)) { // Set the Category Certificate PDF file path for the primary directory $categoryCert = $uploadFilePrimary; // Copy the file to the admin directory if (copy($uploadFilePrimary, $uploadFileAdmin)) { // File copied successfully } else { echo "Error copying Category Certificate PDF file to the admin directory."; } } else { echo "Error uploading Category Certificate."; exit; // Terminate the script if there's an error } } else { echo "Error: " . $_FILES['cat_cert']['error']; exit; // Terminate the script if there's an error } } // if ($_FILES['cat_cert']['error'] === UPLOAD_ERR_OK) { // $uploadDir = 'uploads/cat_cert/'; // Define the directory where you want to store parentsAdhaar files // $uploadFile = $uploadDir . basename($_FILES['cat_cert']['name']); // if (move_uploaded_file($_FILES['cat_cert']['tmp_name'], $uploadFile)) { // // Set the parentsAdhaar file path // $categoryCert = $uploadFile; // } else { // echo "Error uploading Category Certificate."; // exit; // Terminate the script if there's an error // } // } else { // echo "Error: " . $_FILES['cat_cert']['error']; // exit; // Terminate the script if there's an error // } // Bind the parameters mysqli_stmt_bind_param($stmt, 'sssssssssssssssssssssssssssssss', $studentName, $DOB, $studentPhoto, $religion, $nationality, $category, $categoryCert, $address, $parent_email, $motherName, $motherQual, $motherProf, $isMotherExStudent, $mother_pass, $isMotherGovtEmployee, $mother_sector, $fatherName, $fatherQual, $fatherProf, $isFatherGovtEmployee, $father_sector, $tel, $whatsapp, $distanceFromSchool, $medicalCond, $nameAddressPreSchool, $siblingStudying, $siblingNameClass, $latestReportCard, $DOBCert, $parentsAdhaar); // Set parameter values for other input fields $studentName = $_POST['candidate_name']; $DOB = $_POST['dob']; $religion = $_POST['religion']; $nationality = $_POST['nationality']; $category = $_POST['category']; // $categoryCert = isset($_POST['cat_cert']) ? $_POST['cat_cert'] : null; $address = $_POST['address']; $parent_email = $_POST['parent_email']; $motherName = $_POST['mother_name']; $motherQual = $_POST['mother_qualification']; $motherProf = $_POST['mother_profession']; $isMotherExStudent = $_POST['is_mother_ex_student']; $mother_pass = $_POST['mother_pass']; $isMotherGovtEmployee = $_POST['is_mother_govt_employee']; $mother_sector = $_POST['mother_sector']; $fatherName = $_POST['father_name']; $fatherQual = $_POST['father_qualification']; $fatherProf = $_POST['father_profession']; $isFatherGovtEmployee = $_POST['is_father_govt_employee']; $father_sector = $_POST['father_sector']; $tel = $_POST['telephone']; $whatsapp = $_POST['whatsapp']; $qr = "SELECT * FROM shs_registration WHERE Parent_Email='$parent_email' OR Tel='$tel'"; $squery = mysqli_query($con, $qr); $quer = mysqli_num_rows($squery); $distanceFromSchool = $_POST['distance_from_school']; $medicalCond = $_POST['medical']; $nameAddressPreSchool = $_POST['previous_school_address']; $siblingStudying = $_POST['sibling']; $siblingNameClass = isset($_POST['class_section']) ? $_POST['class_section'] : null; // if (mysqli_stmt_execute($stmt)) { // // Redirect to the payment page with user's name and email as parameters // $paymentPageUrl = 'payment.php?name=' . urlencode($_POST['candidate_name']) . '&mother_name=' . urlencode($_POST['mother_name']); // header('Location: ' . $paymentPageUrl); // exit(); // } else { // echo "Error: " . mysqli_error($con); // } // if (mysqli_stmt_execute($stmt)) { // echo '<script>alert("Registration Successfully");</script>'; // echo '<script>window.location.href="payment.php";</script>'; // exit(); if ($quer > 0) { echo "<script> alert('Email or Mobile already exist Please Enter a new one')</script>"; echo '<script>window.location.href="registration.php";</script>'; } elseif (mysqli_stmt_execute($stmt)) { $registrationID = mysqli_insert_id($con); // Store the user's name, mother's name, and Registration_ID in sessions $_SESSION['Registration_ID'] = $registrationID; $_SESSION['user_name'] = $_POST['candidate_name']; $_SESSION['mother_name'] = $_POST['mother_name']; $_SESSION['father_name'] = $_POST['father_name']; $_SESSION['registration_success'] = true; // New session variable // $_SESSION['category'] = $_POST['category']; $studentName = $_POST['candidate_name']; $motherName = $_POST['mother_name']; $fatherName = $_POST['father_name']; $parent_email = $_POST['parent_email']; // Set up email parameters $to = $parent_email; $from = "ssukhchain7536@gmail.com"; $subject = "Sacred Heart Registration"; $body = "Registration ID:". $registrationID. "\n"; $body .= "Candidate Name: " . $studentName. "\n"; $body .= "Email: " . $parent_email. "\n"; $body .= "Mother's Name: " . $motherName. "\n"; $body .= "Father's Name: " . $fatherName. "\n"; // Send email $headers = "From: " . $from . "\r\n"; if (mail($to, $subject, $body, $headers)) { // Redirect to the payment page echo '<script>alert("Registration Successfully, Please Check Your Email Inbox to See your Details");</script>'; echo '<script>window.location.href="payment.php";</script>'; // header('Location: payment.php'); exit(); } else { echo "Error: " . mysqli_error($con); } // Close the prepared statement mysqli_stmt_close($stmt); } else { echo "Error in preparing the statement."; } // Close the database connection mysqli_close($con); } } else { echo "Sorry, there was an error sending your message."; } ?>