hjkhhndndndnd,trt
bnmbertsu,yu,yu,fffffffy,ltdfg
/
home4
/
gofvotmy
/
hindcol
/
Upload FileeE
HOME
<?php // Database connection $username = "gofvotmy_hindu_college"; $password = "%_g}lH?ows+o"; $server = "hinducollegeamritsar.ac.in"; $database = 'gofvotmy_hindu_college'; // Establish connection $con = mysqli_connect($server, $username, $password, $database); // Check connection if (!$con) { die("Connection failed: " . mysqli_connect_error()); } // Retrieve form data $id = $_POST['id']; $name = $_POST['a_name']; $dob = $_POST['a_dob']; $country = $_POST['a_country']; $mobile = $_POST['a_mobile']; $email = $_POST['a_email']; $occupation = $_POST['a_occupation']; $company = $_POST['a_company']; $achieve = $_POST['a_achieve']; $session = $_POST['a_session']; $class = $_POST['a_class']; $highest = $_POST['a_hq']; // $batch = $_POST['a_batch']; $currently = $_POST['a_currently']; $address = $_POST['a_address']; // echo $_FILES['a_photo']; // Upload photo // Upload photo $photo_filename = ''; if (isset($_FILES['a_photo']) && $_FILES['a_photo']['error'] == 0) { $target_dir = "alumni_photos/"; $photo_tmp = $_FILES['a_photo']['tmp_name']; $photo_name = basename($_FILES['a_photo']['name']); // Generate a unique filename by appending a timestamp $photo_filename = $target_dir . uniqid() . '_' . $photo_name; if (move_uploaded_file($photo_tmp, $photo_filename)) { // File uploaded successfully } else { echo "Failed to move uploaded photo file."; } } else { echo "Error uploading photo file: " . $_FILES['a_photo']['error']; } // Upload signature // $sign_filename = ''; // if (isset($_FILES['a_sign']) && $_FILES['a_sign']['error'] == 0) { // $target_dir = "alumni_sign/"; // $sign_tmp = $_FILES['a_sign']['tmp_name']; // $sign_name = basename($_FILES['a_sign']['name']); // // Generate a unique filename by appending a timestamp // $sign_filename = $target_dir . uniqid() . '_' . $sign_name; // if (move_uploaded_file($sign_tmp, $sign_filename)) { // // File uploaded successfully // } else { // echo "Failed to move uploaded signature file."; // } // } else { // echo "Error uploading signature file: " . $_FILES['a_sign']['error']; // } // Debugging // echo "Photo Filename: $photo_filename<br>"; // echo "Sign Filename: $sign_filename<br>"; // SQL query to insert data into database $sql = "INSERT INTO alumni_form (id, a_name, a_photo, a_dob, a_country, a_mobile, a_email, a_occupation, a_company, a_achieve, a_session, a_class, a_hq, a_currently, a_address) VALUES ('$id', '$name', '$photo_filename', '$dob', '$country', '$mobile', '$email', '$occupation', '$company', '$achieve', '$session', '$class', '$highest', '$currently', '$address')"; // Debugging // echo "SQL Query: $sql<br>"; // Check if the query executed successfully if (mysqli_query($con, $sql)) { $message = "Registration successful"; } else { $message = "Error: " . mysqli_error($con); } // Close connection mysqli_close($con); ?> <script> // Display alert message alert("<?php echo $message; ?>"); // Redirect to previous page // window.history.back(); window.location.href = "https://hinducollegeamritsar.ac.in/alumni-regIstration-form.html"; // Prevent default form submission event.preventDefault(); // Optionally, you can use AJAX to submit the form asynchronously // Example using jQuery /* $.ajax({ url: 'your_php_script.php', type: 'POST', data: $('#registration_form').serialize(), success: function(response) { // Handle success response alert('Form submitted successfully!'); $('#registration_form')[0].reset(); // Reset form fields }, error: function(xhr, status, error) { // Handle error response alert('Error: ' + error); } }); */ </script>