set_charset("utf8"); function sanitize_input($data = '') { return htmlspecialchars( stripslashes( trim((string)$data) ) ); } if ($_SERVER["REQUEST_METHOD"] != "POST") { die("Access Denied"); } /* ========================== FORM DATA ========================== */ $applicantName = sanitize_input($_POST['applicantName'] ?? ''); $fatherName = sanitize_input($_POST['fatherName'] ?? ''); $motherName = sanitize_input($_POST['motherName'] ?? ''); $candidateAddress = sanitize_input($_POST['candidateAddress'] ?? ''); $contactNo = sanitize_input($_POST['contactNo'] ?? ''); $gender = sanitize_input($_POST['gender'] ?? ''); $studentEmail = sanitize_input($_POST['studentEmail'] ?? ''); $category = sanitize_input($_POST['category'] ?? ''); $dob = sanitize_input($_POST['dob'] ?? ''); $govtIdType = sanitize_input($_POST['govtIdType'] ?? ''); $govtIdNo = sanitize_input($_POST['govtIdNo'] ?? ''); $qualification = sanitize_input($_POST['qualification'] ?? ''); $semester = sanitize_input($_POST['semester'] ?? ''); $collegeUniversity = sanitize_input($_POST['collegeUniversity'] ?? ''); $trainingInterest = sanitize_input($_POST['trainingInterest'] ?? ''); $expectedJoinDate = sanitize_input($_POST['expectedJoinDate'] ?? ''); $trainingMode = sanitize_input($_POST['trainingMode'] ?? ''); $trainingPayment = sanitize_input($_POST['trainingPayment'] ?? ''); $paymentMode = sanitize_input($_POST['paymentMode'] ?? ''); /* ========================== AUTO GENERATED DATA ========================== */ $regno = "REG" . date("YmdHis"); $bno = 1; $pass = substr(md5(rand()), 0, 8); $status = "Pending"; /* ========================== FILE UPLOAD DIRECTORY ========================== */ $target_dir = "uploads/"; if (!is_dir($target_dir)) { mkdir($target_dir, 0777, true); } function uploadImage($field, $prefix, $maxSize, $target_dir) { if (!isset($_FILES[$field])) { return ''; } if ($_FILES[$field]['error'] != 0) { return ''; } $ext = strtolower(pathinfo($_FILES[$field]['name'], PATHINFO_EXTENSION)); $allowed = ['jpg', 'jpeg', 'png']; if (!in_array($ext, $allowed)) { die($field . " : Only JPG, JPEG and PNG files allowed."); } if ($_FILES[$field]['size'] > $maxSize) { die($field . " : File size exceeded."); } $filename = uniqid($prefix) . "." . $ext; $filepath = $target_dir . $filename; if (!move_uploaded_file($_FILES[$field]['tmp_name'], $filepath)) { die($field . " upload failed."); } return $filepath; } /* ========================== UPLOAD FILES ========================== */ $paymentScreenshot_path = uploadImage( 'paymentScreenshot', 'pay_', 5 * 1024 * 1024, $target_dir ); $passportPhoto_path = uploadImage( 'passportPhoto', 'img_', 2 * 1024 * 1024, $target_dir ); $digitalSignature_path = uploadImage( 'digitalSignature', 'sig_', 1 * 1024 * 1024, $target_dir ); /* ========================== INSERT QUERY ========================== */ $sql = "INSERT INTO training_reg ( regno, applicant_name, father_name, mother_name, candidate_address, contact_no, gender, bno, student_email, category, dob, govt_id_type, govt_id_no, qualification, semester, college_university, training_interest, expected_join_date, training_mode, training_payment, payment_mode, payment_screenshot_path, passport_photo_path, digital_signature_path, pass, status ) VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )"; $stmt = $conn->prepare($sql); $stmt->bind_param( "sssssssissssssssssssssssss", $regno, $applicantName, $fatherName, $motherName, $candidateAddress, $contactNo, $gender, $bno, $studentEmail, $category, $dob, $govtIdType, $govtIdNo, $qualification, $semester, $collegeUniversity, $trainingInterest, $expectedJoinDate, $trainingMode, $trainingPayment, $paymentMode, $paymentScreenshot_path, $passportPhoto_path, $digitalSignature_path, $pass, $status ); $stmt->execute(); $stmt->close(); $conn->close(); ?>