<?php
include_once('../../../db_connect/db.php');
	$block_id=mysqli_real_escape_string($con,$_POST["block_id"]);
	$campus_id=mysqli_real_escape_string($con,$_POST["campus_id"]);
	$title=mysqli_real_escape_string($con,$_POST["title"]);
	$description=mysqli_real_escape_string($con,$_POST["description"]);
	$bedspace=mysqli_real_escape_string($con,$_POST["bedspace"]);
	$added_by=mysqli_real_escape_string($con,$_POST["added_by"]);
	$status=mysqli_real_escape_string($con,$_POST["status"]);


	$check = mysqli_query($con, "SELECT *FROM hostel_rooms WHERE title = '$title' ") or die(mysqli_error($dbc));
	if($check){
	  $sql_verify_title_row=mysqli_num_rows($check);
							if($sql_verify_title_row > 0){
								echo $error='<div class="alert alert-success alert-dismissible" role="alert">
									<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
									<strong>Alert!</strong> This Room already exist, thank you.
								 </div>';

	      }else{
	            //insert into the database
	            $insert= mysqli_query($con, "INSERT INTO hostel_rooms(title,description,hostel_site,hostel_categories,bedspace,added_by,reserved)
	             VALUES('$title','$description','$campus_id','$block_id','$bedspace','$added_by','$status') ") or die(mysqli_error($con));
	             if($insert){
	               echo 1;
	             }else{
								 echo $error='<div class="alert alert-success alert-dismissible" role="alert">
						 			 <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
						 			 <strong>Alert!</strong> Room not saved sucessfully.
						 			</div>';
	             }
	          }
	}



?>
