<?php 

include("config.php");

$dresult=mysql_query("select * from hotel_room WHERE room_no='$_POST[room_no]' ");
$drow=mysql_fetch_array($dresult);

if($drow == ""){
	
mysql_query("ANALYZE TABLE hotel_room"); // important
	
	
$kresult = mysql_query("SHOW TABLE STATUS LIKE 'hotel_room'");
$krow = mysql_fetch_array($kresult);
$id=$krow['Auto_increment'];

mysql_query("INSERT INTO hotel_room (room_no, rtype, rprice,srt_description, description, image) VALUES ( 
'$_POST[room_no]','$_POST[rtype]','$_POST[rprice]','$_POST[srt_description]','$_POST[description]','blank')");

$uploadDir = "room/";

if (!is_dir($uploadDir)) {
    mkdir($uploadDir, 0777, true);
}

foreach ($_FILES['images']['tmp_name'] as $key => $tmp_name) {

    $imageName = $_FILES['images']['name'][$key];
    $tmpPath   = $_FILES['images']['tmp_name'][$key];

    if ($tmpPath != "") {

        // unique name
        $newName = time() . "_" . rand(1000, 9999) . "_" . $imageName;

        // move file
        if (move_uploaded_file($tmpPath, $uploadDir . $newName)) {

            // insert into DB
            $sql = "INSERT INTO room_images (room,image) VALUES ('$id','$newName')";
            mysql_query("$sql");
        }
    }
}



	
header("location:add_room.php");
}else{
header("location:add_room.php?info=Room No  $_POST[room_no] is exist, Please use a new one. ");
	}
?>