<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Student Portal</title>
    <link rel="stylesheet" href="bootstrap-4.6.2-dist/css/bootstrap.min.css">
    <link rel="stylesheet" href="styles.css">

    <link rel="shortcut icon" href="../Image/poly (2).png" type="image/x-icon" />
    <link rel="apple-touch-icon" href="../Image/poly (2).png">
</head>
<body>
<p class="title"></p>
            <p align="center" >
                <img src="images/envillepoly1.png" alt="" width="10%" height="10%" >
            </p>
            <h4 align="center">REGISTRATION</h4>
     <div class="row">
        <div class="col-md-2"></div>
        <div class="col-md-8">
            <form action="register.php" method="POST" enctype="multipart/form-data">
                <h5 style="text-align:center;margin-bottom:40px;">Please Fill in Capital Letters</h5>
                <div class=" row form-group">
                <div class="col-md-6">
                    <label for="name"> First name</label>
                    <input type="text" name="fname" class="form-control" required>
                </div>
                <div class="col-md-6">
                    <label for="name">Surname</label>
                    <input type="text" name="sname" class="form-control" required>    
                </div>
            </div>
            <div class=" row form-group">
                <div class="col-md-6">
                <label for="name">Matric Number</label>
                    <input type="text" name="mat" class="form-control" required>  
                </div>
                <div class="col-md-6">
                <label for="name"> Program type</label>
                   <select name="program" id="" class="form-control" required>
                    <option value="Select program type">Select program type</option>
                    <option value="ND Full TIme">ND Full Time</option>
                    <option value="ND Part Time">ND Part Time</option>
                    
                   </select>
                </div>
            </div>
            <div class=" row form-group">
                <div class="col-md-6">
                <label for="name">Session</label>
                   <select name="sessiond" id="" class="form-control" required>
                    <option value="Select session">Select session</option>
                    <option value="2022/2023">2022/2023</option>
                    <option value="2023/2024">2023/2024</option>
                   </select>   
                </div>
                <div class="col-md-6">
                <label for="name">School</label>
                   <select name="school" id="" class="form-control" required>
                    <option value="Select School">Select School</option>
                    <option value="Science">Science</option>
                    <option value="Management">Management</option>
                    <option value="Engineering">Engineering</option>
                   </select>
                </div>
            </div>
            <div class=" row form-group">
                <div class="col-md-6">
                <label for="name">Department:</label>
                   <select name="Dept" id="" class="form-control" required>
                    <option value="Select Department">Select Department</option>
                    <option value="Computer Science">Computer Science</option>
                    <option value="Business Administration">Business Administration</option>
                    <option value="Computer Engineering">Computer Engineering</option>
                    <option value="Electrical Electronics Engineering">Electrical Electronics Engineering</option>
                   </select>   
                </div>
                <div class="col-md-6">
                <label for="name">Level:</label>
                   <select name="leveld" id="" class="form-control" required>
                    <option value="name0">Select Level</option>
                    <option value="ND1 First Semester">ND1 (First Semester)</option>
                    <option value="ND1 Second Semester">ND1 (Second Semester)</option>
                    <option value="ND2 First Semester">ND2 (First Semester)</option>
                    <option value="ND2 Second Semester">ND2 (Second Semester)</option>
                   </select>
                </div>
            </div>
            <div class=" row form-group">
                <div class="col-md-6">
                <label for="name">Sex</label>
                   <select name="sex" id="" class="form-control" required>
                    <option value="Select">Select</option>
                    <option value="MALE">Male</option>
                    <option value="FEMALE">Female</option>
                    
                   </select>   
                </div>
                <div class="col-md-6">
                <label for="name">Date of Birth</label>
                    <input type="date" name="dob" class="form-control" required>
                </div>
            </div>
            <div class=" row form-group">
                <div class="col-md-6">
                <label for="name">Email</label>
                    <input type="email" name="email" class="form-control" required>    
                </div>
                <div class="col-md-6">
                <label for="name">Phone</label>
                    <input type="text" name="phone" class="form-control" required>
                </div>
            </div>
            <div class=" row form-group">
                <div class="col-md-6">
                <label for="name">Residential Address</label><br>
                   <textarea cols="33" name="addressd" class="form-control" required></textarea>
                </div>
                <div class="col-md-6">
                <label for="name">Place of Birth</label>
                    <input type="text" name="pbirth" class="form-control" required>
                </div>
            </div>
            <div class=" row form-group">
                <div class="col-md-6">
                <label for="name">State of Origin</label>
                    <input type="text" name="sorigin" class="form-control" required>    
                </div>
                <div class="col-md-6">
                <label for="name">Local Government</label>
                    <input type="text" name="lgovt" class="form-control" required>  
                </div>
            </div>
            <div class=" row form-group">
                <div class="col-md-6">
                    <label for="name">Parent/Guardian Name</label>
                    <input type="text" name="pgname" class="form-control" required>
                </div>
                <div class="col-md-6">
                    <label for="name">Parent/Guardian Phone number</label>
                    <input type="text" name="pgnumb" class="form-control" required>    
                </div>
            </div>
            <div class=" row form-group">
                <div class="col-md-6">
                    <label for="name">Passport</label>
                    <input type="file" name="passport" class="form-control" required>
                   
                </div>
                <div class="col-md-6">
                    <!-- <label for="name">Parent/Guardian Phone number</label>
                    <input type="text" name="pgnumb" class="form-control">  -->  
                </div> 
            </div>
            <button type="submit" name="usersubmit" class="btn-success btn-block ">REGISTR</button>
            <p style="margin-bottom:50px;">Already have an account <a href="index.php">Login Here</a></p>
            </form>
            
        </div>
        <div class="col-md-2"></div>
     </div>
    
</body>
</html>
    <?php
    $db=mysqli_connect("localhost","gearcloudtech_studentportaluser","Studentportal@2024","gearcloudtech_studentportal");
    if(mysqli_connect_errno()){
        echo "error connecting to database". mysqli_connect_errno();
    }
    if(isset($_POST['usersubmit'])){
    
    //initialize your variable
    $fname=mysqli_real_escape_string($db, $_POST['fname']); 
    $sname=mysqli_real_escape_string($db, $_POST['sname']); 
    $mat=mysqli_real_escape_string($db, $_POST['mat']);
    $program=mysqli_real_escape_string($db, $_POST['program']);
    $sessiond=mysqli_real_escape_string($db, $_POST['sessiond']);
    $school=mysqli_real_escape_string($db, $_POST['school']);
    $Dept=mysqli_real_escape_string($db, $_POST['Dept']);
    $leveld=mysqli_real_escape_string($db, $_POST['leveld']);
    $sex=mysqli_real_escape_string($db, $_POST['sex']);
    $dob=mysqli_real_escape_string($db, $_POST['dob']);
    $email=mysqli_real_escape_string($db, $_POST['email']);
    $phone=mysqli_real_escape_string($db, $_POST['phone']);
    $addressd=mysqli_real_escape_string($db, $_POST['addressd']);
    $pbirth=mysqli_real_escape_string($db, $_POST['pbirth']);
    $sorigin=mysqli_real_escape_string($db, $_POST['sorigin']);
    $lgovt=mysqli_real_escape_string($db, $_POST['lgovt']);
    $pgname=mysqli_real_escape_string($db, $_POST['pgname']);
    $pgnumb=mysqli_real_escape_string($db, $_POST['pgnumb']);
    
    
    
    //name of the uploaded file
    $passport = $_FILES['passport']['name'];
    
    //destination of the file on the server 
    $destination = 'upload/' .$passport;
    
    //get the file extension
    $extension = pathinfo($passport, PATHINFO_EXTENSION);
    
    //THE PHYSICAL FILE ON A TEMPORARY UPLOADS DIRECTORY ON THE SERVER 
    $file = $_FILES['passport']['tmp_name'];
    $size = $_FILES['passport']['size'];
    
    if(!in_array($extension, ['png', 'jpg', 'jpeg'])){
        echo "Your file extension must be .png, .jpeg, .jpg";
    }elseif($_FILES['passport']['size'] > 1000000){
        echo "<script>alert('File too large!')</script>";
    }else{
       if(move_uploaded_file($file, $destination)){
        $checkmatric = "SELECT * FROM portal WHERE mat = '$mat' AND email = '$email'";
    
        $checkmatric_result = mysqli_query($db, $checkmatric);
    
    if($checkmatric_result->num_rows > 0){
        echo "<script>alert('Matric number or Email already exist')</script>";
    }else{
        $query = "INSERT INTO portal(fname,sname,mat,program,sessiond,school,Dept,leveld,sex,dob,email,phone,addressd,pbirth,sorigin,lgovt,pgname,pgnumb,passport) 
        VALUES('$fname','$sname','$mat','$program','$sessiond','$school','$Dept','$leveld','$sex','$dob','$email','$phone','$addressd','$pbirth','$sorigin','$lgovt','$pgname','$pgnumb','$passport')";
        
        $query_result= mysqli_query($db, $query);
        
        if($query_result){
          
            echo "<script>alert('Registration successful')</script>";
        
        }else{
            echo "<script>alert('Registration successful')</script>";
        }  
    }
    
    }
    
    }
    }
    ?>