<?php
include('../../db_connect/db.php');

//get datas from the form
$title = $_POST['title'];
$campus = $_POST['campus'];
$category=$_POST['selectedValue'];
$description = $_POST['description'];
$date_added = $_POST['date_added'];
$added_by=$_POST['added_by'];
$reserved = $_POST['reserved'];
$bedspace = $_POST['bedspace'];
$user_status=$_POST['user_status'];
$status=$_POST['status'];





//check to see if record already exit
$check = mysqli_query($conn_1, "SELECT *FROM hostel_rooms WHERE title='$title' AND campus_id='$campus' AND block_id='$category' ") or die(mysqli_error($conn_1));
if($check){
  $sql_verify_title_row=mysqli_num_rows($check);
						if($sql_verify_title_row > 0){
							$status='This Hostel Room already exist, thank you.';
      }else{


            //insert into the database
            $insert= mysqli_query($conn_1, "INSERT INTO hostel_rooms(title,description,campus_id,block_id,published,bed_space,reserved,date_added,added_by,status)
             VALUES('$title','$description','$campus','$category','$status','$bedspace','$reserved',NOW(),'$added_by','$user_status')");
             if($insert){
               $status='Successfully added.';
             }else{
               $status='Something went wrong, contact developer.';
             }
          }
}
echo $status;
?>
