<?php
$errmsg='';
$sucmsg='';
if(isset($_POST['addInstituttion'])){
    extract($_POST);
    $errmsg='';
    $sucmsg='';
    
		//update record
	$qry2=mysqli_query($con, "update pci_body SET institution='$institution', currentGrade='$currentGrade', regRoute='$regRoute', regYear='$regYear' where applicant_id='$applicant_idpci' AND id=$editID");
	if($qry2){
		$sucmsg='Successful!';
		echo '<script>window.location = "index.php?page=body";</script>';
	}else{
		$errmsg='Not Successful!';
		//echo mysqli_error($con);
	}
	
    
}



?>

<div class="graph-visual tables-main">
<h2 class="inner-tittle">MEMBERSHIP OF ANY OTHER PROFESSIONAL INSTITUTION(S): (IF ANY)
</h2> Editing Details
	<div class="graph-form">
    		<div class="form-body">
				 <?php
				//GET DETAILS FROM DB
				if(isset($_POST['editID'])){ $editID=$_POST['editID']; }else{ $editID="0"; }
				$q = "Select * from pci_body where applicant_id='$applicant_idpci' and id=$editID Limit 1";
				$qry=mysqli_query($con, $q);
				if($qry){
					
					if(mysqli_num_rows($qry) >0){
						$row=mysqli_fetch_assoc($qry);
						extract($row);
						$sucmsg='Edit the details below then click <b>Update Record</b>';
						
					}else{ $errmsg='No record found!'; }
							
				}else{
					$errmsg='No record found!';
				}
				
				?>
				
    			
               
				<?php 
                if($errmsg!=''){
                    echo '<div class="alert alert-danger">'.$errmsg.'</div>';
                }elseif($sucmsg!=''){
                    echo '<div class="alert alert-success">'.$sucmsg.'</div>';
                
                	//form
                ?>
                <form method="post" name="bodyform" action="index.php?page=bodyeditor"> 
                    <div class="form-group"> 
                        <label>Institution</label> 
                        <input type="text" class="form-control" name="institution" value="<?php echo $institution; ?>" required="" />  
                        <input type="hidden" class="form-control" name="editID" value="<?php echo $editID; ?>" required="" />  
                        
                    </div> 
                    
					<div class="form-group"> 
                        <label>Current Grade</label> 
                        <input type="text" class="form-control" name="currentGrade" value="<?php echo $currentGrade; ?>" required="" /> 
                    </div> 
                    
					<div class="form-group"> 
                        <label>How Membership was achieved</label> 
                        <input type="text" class="form-control" name="regRoute" value="<?php echo $regRoute; ?>" required="" /> 
                    </div> 
					
					<div class="form-group"> 
                        <label>Year Registered/Elected</label> 
                        <!--input type="text" class="form-control" name="regYear" placeholder="e.g 2014" required="" /-->  
                        <select class="form-control" name="regYear" style="width:100%; height:auto">
                         <?php echo "<option>$regYear</option>"; $y=date('Y'); for($iy=$y; $iy>1960; $iy--){ echo "<option>$iy</option>"; } ?>
                        </select>
                    </div> 
                    
                    <div class="form-group"> 
                    <input name="addInstituttion" type="submit" class="btn btn-default" value="Update Record"/> 
                </form> 
    		</div>  
    		
    		<?php
    		 }
    		  ?>
    
    </div>

</div>

<div>
<a href='index.php?page=body'><button class='btn'>Back to Professional Body</button></a>
</div>