<?php
  $db=mysqli_connect("localhost","starrtto_starsstudentportaluser","Starsstudentportal@2024","starrtto_starsstudentportal");
  if(mysqli_connect_errno()){
      echo "error connecting to database". mysqli_connect_errno();
  }

if(isset($_POST['register'])){
   //    get form data
   $title = mysqli_real_escape_string($con, $_POST['title']);
   $fname = mysqli_real_escape_string($con, $_POST['fname']);
   $mname = mysqli_real_escape_string($con, $_POST['mname']);
   $lname = mysqli_real_escape_string($con, $_POST['lname']);
   $saddress = mysqli_real_escape_string($con, $_POST['saddress']);
   $nationality = mysqli_real_escape_string($con, $_POST['nationality']);
   $sstate = mysqli_real_escape_string($con, $_POST['sstate']);
   $city = mysqli_real_escape_string($con, $_POST['city']);
   $Phone = mysqli_real_escape_string($con, $_POST['Phone']);
   $email = mysqli_real_escape_string($con, $_POST['email']);
   $gender = mysqli_real_escape_string($con, $_POST['gender']);
   $programme = mysqli_real_escape_string($con, $_POST['programme']);
   $department = mysqli_real_escape_string($con, $_POST['department']);
   $jambscore = mysqli_real_escape_string($con, $_POST['jambscore']);

   // name of the uploaded file
 $result = $_FILES['result']['name'];

 // destination of the file on the server
 $destination = 'upload/' . $result;

 // get the file extension
 $extension = pathinfo($result, PATHINFO_EXTENSION);

 // the physical file on a temporary uploads directory on the server
 $file = $_FILES['result']['tmp_name'];
 $size = $_FILES['result']['size'];

 if (!in_array($extension, ['pdf', 'jpg','png','jpeg'])) {
   echo "You file extension must be  .pdf, .jpg, .png, or .jpeg ";
} elseif ($_FILES['result']['size'] > 1000000) { // file shouldn't be larger than 1Megabyte
   echo '<script>alert("File too large!")</script>';
} else {
   // move the uploaded (temporary) file to the specified destination
   if (move_uploaded_file($file, $destination)) {

$query = "INSERT INTO new_student_reg(title, fname, mname, lname, saddress, nationality, sstate, city, Phone, email, gender, programme, department, jambscore , result) 
VALUES('$title','$fname', '$mname', '$lname', '$saddress', '$nationality', '$sstate', '$city', '$Phone', '$email', '$gender', '$programme','$department', '$jambscore', '$result')";

       if (mysqli_query($con, $query)) {
         echo "<script>alert('Registration Successfully')</script>";  
       }
   } else {
      echo "<script>alert('Registration Not Successfully')</script>";  
   }
}

}
