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


	$check = mysqli_query($conn_1, "SELECT *FROM hostel_blocks WHERE title = '$title' AND campus_id ='$campus_id' ") or die(mysqli_error($conn_1));
	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 Block already exist, thank you.
								 </div>';

	      }else{
	            //insert into the database
	            $insert= mysqli_query($conn_1, "INSERT INTO hostel_blocks(title,description,campus_id,bed_space,gender,hostel_amount,added_by,reserved)
	             VALUES('$title','$description','$campus_id','$bedspace','$gender','$amount','$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> Campus not saved sucessfully.
						 			</div>';
	             }
	          }
	}



?>
