
<?php include('../conn.php');
$page='Edit room';
if (isset($_GET['id'])) {
$id=mysqli_real_escape_string($conn, $_GET['id']);
$id2=base64_decode($id); }
?>

<!DOCTYPE html>
<html lang="en">
<?php include("../common/head.php")?>
<style>
    .modal{
        background-color:black;
    }
    form{
        background-color:black;
        color:white;
    }
    label{
        font-size:20px;

    }
    .edit-body{
        margin:100px;
    }

    input,select{
        background-color:rgba(0, 0, 0, 0) !important;
}
</style>
<body>
                 <!-- Modal -->
                 <?php 
$sql = "SELECT * FROM rooms WHERE id='$id2' ";
$result=mysqli_query($conn,$sql);
    $row=mysqli_fetch_array($result);
?>
        <div class="edit-header">
          <h3 class="edit-tittle text-center " id="exampleModalLabel">Edit Room</h3>
        </div>
        <div class="edit-body text-center">
        <form method="post" class="text-dark bg-light">

<div class="form-group">
      <label for="exampleFormControlSelect1">Room Category</label>
      <select class="form-control" name="cat" id="exampleFormControlSelect1">
      <option value="<?php echo $row['cat']?>"><?php echo $row['cat']?></option>
      <option value="Deluxe">Deluxe</option>
        <option value="Standard">Standard</option>
         <option value="Executive">Executive</option></option>
        <option value="Normal">Normal</option>
      </select>
    </div>

    <div class="form-group">
      <label for="exampleFormControlInput1">Room number</label>
      <input type="text" class="form-control" name="number" id="exampleFormControlInput1" value="<?php echo $row['number']?>" >
    </div>

    <div class="form-group">
      <label for="exampleFormControlInput1">Price</label>
      <input type="number" class="form-control" name="price" id="exampleFormControlInput1" Value="<?php echo $row['price']?>"  >
    </div>

    <div class="form-group">
      <label for="exampleFormControlInput1">Amenities</label>
      <input type="text" class="form-control" name="amenities" id="exampleFormControlInput1" value="<?php echo $row['amenities']?>"  >
    </div>

    <input type="hidden" name="date" value="<?php echo date("F j, Y") ?>">
    <input type="hidden" name="by" value="<?php echo $id_user ?>">
    
      <button class="btn btn-success btn-sm"  name="submit">Submit</button>
  </form>
        </div>
        <div class="modal-footer">
        </div>

        <?php 





if(isset($_POST['submit'])){
 
    $cat=$_POST['cat'];
     $number=$_POST['number'];
     $price=$_POST['price'];
     $number=$_POST['number'];
    $amenities=$_POST['amenities'];
     $by=$_POST['by'];
     $date=$_POST['date'];


    
     

		$sql = "UPDATE `rooms` SET `cat`='$cat',`number`='$number',`price`='$price',`amenities`='$amenities',`by`='$by',`date`='$date' WHERE id=$id2";
		if(mysqli_query($conn,$sql)){

      echo"<script>alert('Room succefully updated'); window.location.href='../room'</script>";
		}
		else{
		  echo 'Error: '.mysqli_error($conn);
		}
    

}



?>

    </body>
</html>