<?php include("db.php"); ?>
    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <title>Document</title>
        <link rel="stylesheet" href="bootstrap-4.6.2-dist/css/bootstrap.min.css">
 
    </head>
    <body>
    <!-- <h3>Hostel Accommodation Form</h3> -->
                <!-- <hr/> -->
                <div class="container">
					<div class="row">
                    <div class="col-md-3"> </div>
                    <div class="col-md-6">
                    <form method="post" action="update.php" enctype="multipart/form-data">
                    <p style="font-size:13px; padding:bottom 70%;margin-bottom: 50%;"><b> </b></p>
                    <p><b> UPDATE STUDENT PARTICULARS</b></p>
                   <div class="row form-group">
                       <div class="col-md-6">
                            <input type="text" name="surname" class="form-control" placeholder="Surname" required>
                       </div>
                       <div class="col-md-6">
                            <input type="text" name="othernames" class="form-control" placeholder="Other Names" required>
                       </div>
                   </div>
                   
                   <div class="row form-group">
                       <div class="col-md-6">
                       <select name="department_name" value="<?php if(isset($_POST['department_name'])){echo $_POST['department_name'];} ?>" id="" class="form-control" required>
									   <option value="">Select department</option>
											<?php
												$sql = mysqli_query($db, "SELECT * from department");
												while($row = mysqli_fetch_array($sql))
												{
													?>
													<option value="<?php echo htmlentities($row['department_name']); ?>"><?php echo htmlentities($row['department_name']); ?></option>

												<?php
													}
												?>
									   </select>
                       </div>
                       <div class="col-md-6">
                            <input type="type" name="residential_address" class="form-control"placeholder="Residential Address" required>
                       </div>
                   </div>
                   
                   <div class="row form-group">
                       <div class="col-md-6">
                       <input type="text" name="aaddress" class="form-control" placeholder="Address" required>
                       </div>
                       <div class="col-md-6">
                       <input type="tel" name="nameguardian" class="form-control" placeholder="Name of Guardian" required>
                       </div>
                   </div>
                   
                   <div class="row form-group">
                       <div class="col-md-12">
                       <input type="tel" name="phoneall" class="form-control" placeholder="Phone Number: Father, Mother, Guardian" required>
                       </div>
                       
                   </div>
                   
                   
                                                             
                    <!--<input type="submit" name="submit" clas="btn btn-primary btn-block" value="Submit">-->
                    <button type="submit" name="hostelsubmit" class="btn btn-success btn-block">Submit</button>
                </form>
                    
					</div>
				</div>
                </div>
                <div class="row" style="margin-top:50px;">
                        <div class="col-md-6">
                            <a href="index.php?env=hostel" style="color:#ffffff;text-decoration:none;"> 
                                <!-- <button type="button" class="btn btn-primary btn-block"><i class="fa fa-arrow-left"></i> Go back</button> -->
                            </a>
                        </div>
                        <div class="col-md-3">
                        
                        </div>
                    </div>


<?php
;
if(isset($_POST['updateid '])){
    $student_id = mysqli_real_escape_string($db, $_POST['student_id']);
    $surname = mysqli_real_escape_string($db, $_POST['surname']);
    $othernames = mysqli_real_escape_string($db, $_POST['othernames']);
    $department_name = mysqli_real_escape_string($db, $_POST['department_name']);
      $residential_address = mysqli_real_escape_string($db, $_POST['residential_address']);
     $aaddress = mysqli_real_escape_string($db, $_POST['aaddress']);
    $nameguardian = mysqli_real_escape_string($db, $_POST['nameguardian']);
    
    $phoneall = mysqli_real_escape_string($db, $_POST['phoneall']);
 $query = "update hostel_table set student_id=$student_id,surname='$surname',othernames='$othernames','department_name='$department_name',
     residential_address='$residential_address',aaddress='$aaddress', nameguardian='$nameguardian', phoneall='$phoneall',
     WHERE student_id='$student_id'";
       
       if (mysqli_query($db, $query)) {
        echo "<script>alert('Update Successfully')</script>";  
      
   } else {
      echo "<script>alert(' Not Successfully')</script>";  
   }
    }
?>
    </body>
    </html>           