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

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


//get hostel site
$result = mysqli_query($conn_1,"SELECT id FROM hostel_campuses WHERE title = '$campus' ") or die(mysqli_error($conn_1));
  $ok = mysqli_fetch_assoc($result);
  $site_id = $ok['id'];



//check to see if record already exit
$check = mysqli_query($conn_1, "SELECT *FROM hostel_blocks WHERE title='$title' AND campus_id='$site_id' ") 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 Block already exist, thank you.';
      }else{


            //insert into the database
            $insert= mysqli_query($conn_1, "INSERT INTO hostel_blocks(title,description,campus_id,bed_space,gender,status,hostel_amount,date_added,added_by,reserved)
             VALUES('$title','$description','$site_id','$bedspace','$gender','$status','$amount',NOW(),'$added_by','$reserved')");
             if($insert){
               $status='Successfully added.';
             }else{
               $status='Something went wrong, contact developer.';
             }
          }
}
echo $status;
?>
