<?php
$hotel_name=$_POST['hotel_name'];
$room_type=$_POST['room_type'];
$price=$_POST['price'];
$no_of_rooms=$_POST['no_of_rooms'];
$facilities=$_POST['facilities'];
$hotel_id=$_POST['hotel_id'];
$hotel_star=$_POST['hotel_star'];
require_once "config.php";

$uploads_dir = 'uploads/';


        $tmp_name = $_FILES["file"]["tmp_name"];
        // basename() may prevent file traversal attacks;
        // further validation/sanitation of the filename may be appropriate
        $name = time()."_".($_FILES["file"]["name"]);
        move_uploaded_file($tmp_name, "$uploads_dir/$name");
  

$sql="select * from rooms where hotel_name='".$hotel_name."' and room_type='".$room_type."'";
$query=mysqli_query($con,$sql);
if($query==false){
    die(mysqli_error($con));
}
if($result=mysqli_fetch_array($query)){
    die("Room Type exists");
}
        
        
        
$count=0;

$sql="insert into rooms(hotel_id,hotel_star,hotel_name,room_type,price,total_no_of_rooms,facilities,thumbnail_img,created_on) values('".$hotel_id."','".$hotel_star."','".$hotel_name."','".$room_type."','".$price."','".$no_of_rooms."','".$facilities."','".$name."',now())";
$query=mysqli_query($con,$sql);
$count=$count+mysqli_affected_rows($con);


if($query==false){
    die(mysqli_error($con));
}
echo $count;


?>