<?php
$errmsg='';
$sucmsg='';


if(isset($_POST['update'])){
    extract($_POST);
    $errmsg='';
    $sucmsg='';
    
		//update record
	$qry2=mysqli_query($con, "delete from epci_postgraduate where applicant_id='$applicant_idpci'");
	$qry2=mysqli_query($con, "INSERT INTO epci_postgraduate (applicant_id, year_range) values ('$applicant_idpci', '$year_range')");
	if($qry2){
		$sucmsg='Successful!';
	}else{
		$errmsg='Not Successful!';
	}
	
    
}






//GET DETAILS FROM DB
	
	$q = "Select * from epci_postgraduate where applicant_id='$applicant_idpci'";
    $qry=mysqli_query($con, $q);
	if($qry){
		
		if(mysqli_num_rows($qry) >0){
			$row=mysqli_fetch_assoc($qry);
			extract($row);
            $year_range_available =1;
			
		}else{ $errmsg='details not found!'; }
				
	}else{
		$errmsg='details not found!';
	}
?>

 
 
<div class="graph-visual tables-main">
<h2 class="inner-tittle">PROFESSIONAL EXPERIENCE  </h2>
	<div class="graph-form">
    		<div class="form-body">
    			 
                <?php 
                if($errmsg!=''){
                    echo '<div class="alert alert-danger">'.$errmsg.'</div>';
                }elseif($sucmsg!=''){
                    echo '<div class="alert alert-success">'.$sucmsg.'</div>';
                }
                
                ?><form method="POST" name="postgraduateform" action="index.php?page=postgraduate"> 
                    <div class="form-group"> 
                        <label>Years of Professional Experience</label> 
                        <select class="form-control" name="year_range" required="" style="height:auto">
                         
                         <option <?php if($year_range=="10-15"){ echo "selected"; }; ?>>10-15</option>
                         <option <?php if($year_range=="16-19"){ echo "selected"; }; ?>>16-19</option>
                         <option <?php if($year_range=="20 and above"){ echo "selected"; }; ?>>20 and above</option>
                         
                        </select>  
                    </div> 
                    
					
                    <input name="update" type="submit" class="btn btn-default" value="Update Details"/> 
                </form> 
    		</div>
    
    </div>

</div>


   
<?php

 echo "<div>";
 echo "  <a href='?page=body'><button class='btn'>Back</button></a>"; 
 if($year_range_available==1){
    //chk value
    if($year_range =="5-9"){
        //prompt user not qualified
        //exit
        //disallow login
        echo '<script>window.alert("You are not eligible for this application");
        window.location = "https://niqs.org.ng/onlineapplication/epci/logout.php";
        </script>';
        
    }elseif(($year_range !="5-9")&&($year_range !="")){
        //qualified
        echo "  <a href='?page=experience'><button class='btn'>Next</button></a>"; 
    }
       
 }
 
 echo "</div>";

?>