Muncul Pesan tanpa loading

Marini Stefani · Sep 13, 2012
Hallo Mas Ellyx,salam kenal ya..
Begini mas, saya ada tugas kuliah mmbuat reservasi hotel sederhana..saya punya 2 tabel..
1.tabel j_kamar
fielnya--->id_kamar,nama,all,booking,sisa,price
2tabel reservasi
fieldnya--->id,id_kamar,nama,t_lahir,tgl_lahir,jk,alamat,kota,email,telp,adult,children,check_in,check_out,lama,bill
saya punya script reservasi.php,,,sepert dbwh ini,,pas user memilih kamar,otomatis kamar berkurang di field:sisa, tabel:j_tabel,,,,nahhh pada saat kamar telah habis dibooking yg artinya field sisa nilainya 0,
pd saat user memilih tu kamar(habis dibooking) muncul pesan dibawah <selsect optionnya> "Maaf Kamar saat ini tidak tersedia" tanpa loading mas,,dan otomatis submitnya ga bisa..
<?php
//validasi
if($_POST){
	$nama=$_POST['nama'];
	$t_lahir=$_POST['t_lahir'];
	$tgl_lahir=$_POST['tgl_lahir'];
	$alamat=$_POST['alamat'];
	$kota=$_POST['kota'];
	$email=$_POST['email'];
	$telp=$_POST['telp'];
	$adult=$_POST['adult'];
	$children=$_POST['children'];
	$telp=$_POST['telp'];
	$cek_mail = "^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+))$";

	$error=array();
	if(empty($nama)){
	$error['nama']='NAMA TIDAK BOLEH KOSONG';
	}
	if(empty($t_lahir)){
	$error['t_lahir']='TEMPAT LAHIR TIDAK BOLEH KOSONG';
	}
	if(empty($alamat)){
	$error['alamat']='ALAMAT TIDAK BOLEH KOSONG';
	}
if(empty($kota)){
	$error['kota']='KOTA TIDAK BOLEH KOSONG';
	}
	if(empty($email)){
	$error['email']='EMAIL TIDAK BOLEH KOSONG';
	}
if(empty($telp)){
	$error['telp']='TELP TIDAK BOLEH KOSONG';
	}
	if(empty($adult)){
	$error['adult']='ADULT TIDAK BOLEH KOSONG';
	}
if(!eregi($cek_mail,($_POST['email']))){ 
	$error['email1']='EMAIL TIDAK VALID!!SILAHKAN MASUKKAN EMAIL YANG VALID';
	}

	if(empty($error)){
	//end validasi
//proses input data
if (isset($_POST['input'])) {
	$nama = addslashes (strip_tags ($_POST['nama']));
	$t_lahir = addslashes (strip_tags ($_POST['t_lahir']));
	$tgllahir = $_POST['tgl']."-".$_POST['bln']."-".$_POST['thn'];
	$jk = $_POST['jk'];
	$alamat = addslashes (strip_tags ($_POST['alamat']));
	$telp = addslashes (strip_tags ($_POST['telp']));
	$email = addslashes (strip_tags ($_POST['email']));
	$kota = addslashes (strip_tags ($_POST['kota']));
	$id_kamar=$_POST['roomid'];
	$in= $_POST['tgl1']."-".$_POST['bln1']."-".$_POST['thn1'];
	$out= $_POST['tgl2']."-".$_POST['bln2']."-".$_POST['thn2'];
	$adult=$_POST['adult'];
	$children=$_POST['children'];
$sql1=mysql_query("select * from j_kamar where id_kamar='$id_kamar'");
$row1=mysql_fetch_array($sql1);
$bill=stripslashes($row1['price']);
/*$start = '2012-12-12';
$end = '2012-12-15';*/
$diff = abs(strtotime($in) - strtotime($out));
$day = ceil($diff/(60*60*24)) + 1;
$lama=$day;
$bill=($day * $bill);
/*echo 'Lama Menginap: '.$day.' hari<br/>';*/
 
/*$sewa = 2000;
echo 'Sewa:'.($day * $bill);*/
	//sisa dan booking dikurangi dari tabel j_kamar
$sisa=stripslashes($row1['sisa']);
$booking=stripslashes($row1['booking']);
$h_sisa=$sisa-1;
$h_booking=$booking+1;
//update j_kamar
$updatekamar=mysql_query("update j_kamar set sisa='$h_sisa',booking='$h_booking' where id_kamar='$id_kamar'");
	}
	//insert ke tabel
	$query = "INSERT INTO reservasi VALUES('','$id_kamar','$nama','$t_lahir','$tgllahir','$jk','$alamat','$kota','$email','$telp','$adult','$children','$in','$out','$lama','$bill')";
	$sql = mysql_query ($query) or die (mysql_error());
	if ($sql) {
			echo"<script>alert('Data Berhasil Ditambah')
			location.replace('reservasi_hasil.php?id=$id_kamar&nm=$nama')</script>";
	} else {
			echo"<script>alert('Data Gagal Ditambah')
			location.replace('reservasi.php')</script>";
	}
}
}

?>
<? include "header.php";  ?>
<!-- header ends -->
        <!-- content begins -->
                <div class="cont_top"></div>
       			<div id="content">
				<? include "side.php";  ?>
                     
                        <div id="left">
                            <h1>Reservasi Kamar Hotel</h1>
                              
                            
	<form action="" method="post" enctype="multipart/form-data" name="input" id="form1" >

<table border="2" width="85%">
		<tr>
		<td colspan="3"><span style="font-size:16px; font-weight:bold;">Informasi Data diri</span></td>
		</tr>
		<tr>
		<td width="40%">Nama<br />
		<input type="text" name="nama" value="<? if($error){echo isset($_POST['nama']) ? $_POST['nama'] : '' ; } ?>"  />
		<div style="color:red"><? echo isset($error['nama']) ? $error['nama'] :''; ?></div>		</td>
		<td colspan="2"></td>
		<td>Jenis Kelamin <br />
		<input type="radio" value="L" name="jk"/>Laki-Laki&nbsp;&nbsp;<input type="radio" value="P" name="jk" />Perempuan</td><td></td>
		</tr>
		<tr>
		<td>Tempat Lahir<br />
		<input type="text" name="t_lahir" value="<? if($error){echo isset($_POST['t_lahir']) ? $_POST['t_lahir'] : '' ; } ?>"  />
		<div style="color:red"><? echo isset($error['t_lahir']) ? $error['t_lahir'] :''; ?></div>		</td>
		<td colspan="2"></td>
		<td>Tgl Lahir<br />
		<select name="tgl">
		<?php
					for ($i=1; $i<=31; $i++) {
						$tg = ($i<10) ? "0$i" : $i;
						echo "<option value='$tg'>$tg</option>";	
					}
				?>
        </select>
       -  
       <select name="bln">
	   <?php
					for ($i=1; $i<=12; $i++) {
						$bl = ($i<10) ? "0$i" : $i;
						echo "<option value='$bl'>$bl</option>";	
					}
				?>
          </select>
        -
        <select name="thn" >
		<?php
					for ($i=1970; $i<=2000; $i++) {
						echo "<option value='$i'>$i</option>";	
					}
				?>
          </select></td>
		<td></td>
		</tr>
		
		<tr height="20">
		<td colspan="3"><span style="font-size:16px; font-weight:bold;">Your Contac</span></td>
		</tr>
		
		</tr>
		<tr>
		<td>Alamat<br />
		<input type="text" name="alamat"  value="<? if($error){echo isset($_POST['alamat']) ? $_POST['alamat'] : '' ; } ?>" />
		<div style="color:red"><? echo isset($error['alamat']) ? $error['alamat'] :''; ?></div>		</td>
		<td colspan="2"></td>
		<td>Kota<br />
		<input type="text" name="kota" value="<? if($error){echo isset($_POST['kota']) ? $_POST['kota'] : '' ; } ?>" />
		<div style="color:red"><? echo isset($error['kota']) ? $error['kota'] :''; ?></div>		</td>
		<td></td>
		</tr>
		<tr>
		<td>Email<br />
		<input type="text" name="email" <? if($error){echo isset($_POST['email']) ? $_POST['email'] : '' ; } ?>  />
		<div style="color:red"><? echo isset($error['email']) ? $error['email'] :''; ?><? echo isset($error['email1']) ? $error['email1'] : '' ; ?></div>		</td>
		<td width="30"></td>
		</tr>
		<tr>
		<td>Telp<br />
		<input type="text" name="telp" <? if($error){echo isset($_POST['telp']) ? $_POST['telp'] : '' ; } ?> />
		<div style="color:red"><? echo isset($error['telp']) ? $error['telp'] :''; ?></div>		</td>
		<td></td>
		</tr>
		
		<tr>
		<td colspan="3"><span style="font-size:16px; font-weight:bold;">Your Reservation</span></td>
		</tr>
		<td>Room Type<br />
		 <select name="roomid" id="roomid" >
        <option value="" >Select Room</option>
           <?  $sql=mysql_query("select * from j_kamar ");
		while($row=mysql_fetch_array($sql)){
		
		echo "<option value='$row[id_kamar]'>$row[nama]</option>";
		} ?>
         </select></td>
		<td><? /*if($row1['sisa']==0)	{
				echo "Maaf kamar sedng kosong";
				}*/ ?></td>
		<? /*$no=1;
			$sql=mysql_query("select * from j_kamar");
			while($row=mysql_fetch_array($sql)	{
			$jenis=stripslashes($row['jenis'])*/;
			?>
		<tr>
		<td>Adult<br />
		<input type="text" name="adult"  value="<? if($error){echo isset($_POST['adult']) ? $_POST['adult'] : '' ; } ?>"/>
		<div style="color:red"><? echo isset($error['adult']) ? $error['adult'] :''; ?></div>		</td>
		<td colspan="2"></td>
				<td>Children<br />
		<input type="text" name="children" /> </td>
		<td></td>
		</tr>
		<tr>
			<td>Check In<br />
			 <select name="tgl1">
		<?php
					for ($i=1; $i<=31; $i++) {
						$tg = ($i<10) ? "0$i" : $i;
						echo "<option value='$tg'>$tg</option>";	
					}
				?>
        </select>
       -  
       <select name="bln1">
	   <?php
					for ($i=1; $i<=12; $i++) {
						$bl = ($i<10) ? "0$i" : $i;
						echo "<option value='$bl'>$bl</option>";	
					}
				?>
          </select>
        -
               <select name="thn1">
		
            <option value="<?php echo date("Y"); ?>" selected="selected"><?php echo date("Y"); ?></option>
			</select> </td>
<td colspan="2"></td>		
  				<td>Check Out<br />
			<select name="tgl2">
		<?php
					for ($i=1; $i<=31; $i++) {
						$tg = ($i<10) ? "0$i" : $i;
						echo "<option value='$tg'>$tg</option>";	
					}
				?>
        </select>
       -  
       <select name="bln2">
	   <?php
					for ($i=1; $i<=12; $i++) {
						$bl = ($i<10) ? "0$i" : $i;
						echo "<option value='$bl'>$bl</option>";	
					}
				?>
          </select>
        -
        <select name="thn2">
		
            <option value="<?php echo date("Y"); ?>" selected="selected"><?php echo date("Y"); ?></option>
			</select></td>
<td></td>		
		  </tr>
		  <tr>
		  		<td height="40" align="right" style="vertical-align:bottom"><input type="submit" name="input" value="Send" />&nbsp;&nbsp;<input type="reset" value="Reset" /></td>
		  </tr>
	</table>
</form>

Maaf mas klu pertanyaan saya berbelit2,,
Sebelumnya terima Kasih Mas Ellyx Christian
Silahkan login untuk menjawab!
0
Loading...
Robert James M · Sep 13, 2012 · 0 Suka · 0 Tidak Suka
kayanya itu pake validasi deh,
0
Loading...
Ellyx Christian · Sep 14, 2012 · 0 Suka · 0 Tidak Suka
caranya menggunakan AJAX. Agar lebih mudah saya akan kasi contoh menggunakan lib jquery, sebelumnya silahkan download jquery.
Pertama buat sebuah file namanya cek_kamar.php
<?php
//jangan lupa konek ke database
$idKamar = $_GET['id'];
$hs =  mysql_query("select * from j_kamar where id_kamar='".$idKamar."'");
$data = mysql_fetch_assoc($hs);
header("Content-Type: text/json");
echo json_encode($data);
kemudian di file reservasi.php tambahkan javascript berikut:
<script type="text/javascript" src="jquery.js"></script> <!-- tambahkan script jquery, sesuaikan dengan lokasi di websitemu -->
<script type="text/javascript">
$(document).ready(function(){
	$('#roomid').change(function(){
		var idkamar = $(this).val();
		$.ajax({
			url:'cek_kamar.php?id='+idkamar,
			dataType:'json',
			success:function(hasil){
				var sisa = parseFloat(hasil.sisa);
				if(sisa <= 0){
					alert('Anda tidak bisa booking kamar ini');
					$(':submit').attr('disabled','disabled');
				}else{
					$(':submit').removeAttr('disabled');
				}
				
			}
		});
	});
});
</script>
0
Loading...
Marini Stefani · Sep 16, 2012 · 0 Suka · 0 Tidak Suka
Error Mas Ellyx Christian
ini errornya
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\xampp\htdocs\hotel2\reservasi.php:9) in C:\Program Files\xampp\htdocs\hotel2\cek_kamar.php on line 6
Fatal error: Call to undefined function json_encode() in C:\Program Files\xampp\htdocs\hotel2\cek_kamar.php on line 7

padahal sdh aku tambahin seperti kata mas Ellyx,seperti ini
<? include "cek_kamar.php"; ?>  

<script type="text/javascript" src="lib/jquery.1.4.2.js"></script>
	<script type="text/javascript" src="lib/jquery.custom.js"></script>
	<script type="text/javascript">
$(document).ready(function(){
	$('#roomid').change(function(){
		var idkamar = $(this).val();
		$.ajax({
			url:'cek_kamar.php?id='+idkamar,
			dataType:'json',
			success:function(hasil){
				var sisa = parseFloat(hasil.sisa);
				if(sisa <= 0){
					alert('Anda tidak bisa booking kamar ini');
					$(':submit').attr('disabled','disabled');
				}else{
					$(':submit').removeAttr('disabled');
				}
 
			}
		});
	});
});
</script>
<? include "konek.php";  ?>

Tolong Mas Ellyx ya..
0
Loading...
Ellyx Christian · Sep 16, 2012 · 0 Suka · 0 Tidak Suka
tolong ikuti apa yang saya kasi tahu sebelumnya. Apa yang saya katakan itu yang perlu dilakukan, pertama buat file cek_kamar.php tanpa include ke file lain. kemudian ubah file reserveri.php dengan menambahkan javascript yang saya kasi tahu.
0
Loading...
Marini Stefani · Sep 17, 2012 · 0 Suka · 0 Tidak Suka
sdh saya hapus includenya Mas Ellyx Christian sudah saya ikuti sperti yg mas katakan,,
tp ga ngefek mas,,saat sisa kmr niainya '0' msh bisa diselect..ga da psn yg muncul..dan reservasi sukses..
ini scrip reservasi.php saya mas
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Grand Zuri</title>
<meta name="keywords" content="" />
<meta name="description" content="" />
<link href="styles.css" rel="stylesheet" type="text/css" />
<!-- Begin JavaScript -->
<script type="text/javascript" src="lib/jquery.1.4.2.js"></script>
	<script type="text/javascript" src="lib/jquery.custom.js"></script>
<script type="text/javascript" src="lib/jquery-1.8.1.js"></script> <!-- tambahkan script jquery, sesuaikan dengan lokasi di websitemu -->
<script type="text/javascript">
$(document).ready(function(){
	$('#roomid').change(function(){
		var idkamar = $(this).val();
		$.ajax({
			url:'cek_kamar.php?id='+idkamar,
			dataType:'json',
			success:function(hasil){
				var sisa = parseFloat(hasil.sisa);
				if(sisa <= 0){
					alert('Anda tidak bisa booking kamar ini');
					$(':submit').attr('disabled','disabled');
				}else{
					$(':submit').removeAttr('disabled');
				}
 
			}
		});
	});
});
</script>
<? include "konek.php";  ?>
<style type="text/css">
body {
	background-color: #FFFFFF;
}
</style>
</head>
<body>
<?php
//validasi
if($_POST){
	$nama=$_POST['nama'];
	$t_lahir=$_POST['t_lahir'];
	$tgl_lahir=$_POST['tgl_lahir'];
	$alamat=$_POST['alamat'];
	$kota=$_POST['kota'];
	$email=$_POST['email'];
	$telp=$_POST['telp'];
	$adult=$_POST['adult'];
	$children=$_POST['children'];
	$telp=$_POST['telp'];
	$cek_mail = "^([._a-z0-9-]+[._a-z0-9-]*)@(([a-z0-9-]+\.)*([a-z0-9-]+))$";

	$error=array();
	if(empty($nama)){
	$error['nama']='NAMA TIDAK BOLEH KOSONG';
	}
	if(empty($t_lahir)){
	$error['t_lahir']='TEMPAT LAHIR TIDAK BOLEH KOSONG';
	}
	if(empty($alamat)){
	$error['alamat']='ALAMAT TIDAK BOLEH KOSONG';
	}
if(empty($kota)){
	$error['kota']='KOTA TIDAK BOLEH KOSONG';
	}
	if(empty($email)){
	$error['email']='EMAIL TIDAK BOLEH KOSONG';
	}
if(empty($telp)){
	$error['telp']='TELP TIDAK BOLEH KOSONG';
	}
	if(empty($adult)){
	$error['adult']='ADULT TIDAK BOLEH KOSONG';
	}
if(!eregi($cek_mail,($_POST['email']))){ 
	$error['email1']='EMAIL TIDAK VALID!!SILAHKAN MASUKKAN EMAIL YANG VALID';
	}

	if(empty($error)){
	//end validasi
//proses input data
if (isset($_POST['input'])) {
	$nama = addslashes (strip_tags ($_POST['nama']));
	$t_lahir = addslashes (strip_tags ($_POST['t_lahir']));
	$tgllahir = $_POST['tgl']."-".$_POST['bln']."-".$_POST['thn'];
	$jk = $_POST['jk'];
	$alamat = addslashes (strip_tags ($_POST['alamat']));
	$telp = addslashes (strip_tags ($_POST['telp']));
	$email = addslashes (strip_tags ($_POST['email']));
	$kota = addslashes (strip_tags ($_POST['kota']));
	$id_kamar=$_POST['roomid'];
	$adult=$_POST['adult'];
	$children=$_POST['children'];
$sql1=mysql_query("select * from j_kamar where id_kamar='$id_kamar'");
$row1=mysql_fetch_array($sql1);
$bill=stripslashes($row1['price']);
	$in= $_POST['tgl1']."-".$_POST['bln1']."-".$_POST['thn1'];
	$out= $_POST['tgl2']."-".$_POST['bln2']."-".$_POST['thn2'];

if(strtotime($in) > strtotime($out)){
			echo"<script>alert('Tanggal Yang Anda Masukkan Invalid<br>Silahkan coba Lagi')
			location.replace('reservasi.php')</script>";
		} else {

$diff = abs(strtotime($in) - strtotime($out));
$day = ceil($diff/(60*60*24)) + 1;
$lama=$day;
$bill=($day * $bill);
$sisa=stripslashes($row1['sisa']);
$booking=stripslashes($row1['booking']);
$h_sisa=$sisa-1;
$h_booking=$booking+1;
$updatekamar=mysql_query("update j_kamar set sisa='$h_sisa',booking='$h_booking' where id_kamar='$id_kamar'");
	
	//insert ke tabel
	$query = "INSERT INTO reservasi VALUES('','$id_kamar','$nama','$t_lahir','$tgllahir','$jk','$alamat','$kota','$email','$telp','$adult','$children','$in','$out','$lama','$bill')";
	$sql = mysql_query ($query) or die (mysql_error());
	if ($sql) {
			echo"<script>alert('Data Berhasil Ditambah')
			location.replace('reservasi_hasil.php?id=$id_kamar&nm=$nama')</script>";
	} else {
			echo"<script>alert('Data Gagal Ditambah')
			location.replace('reservasi.php')</script>";
	}
}
}
}
}
?>

<div id="bg_img">
<div id="main">
<div id="main_img">
<!-- header begins -->
<? include "header.php";  ?>
<!-- header ends -->
        <!-- content begins -->
                <div class="cont_top"></div>
       			<div id="content">
				<? include "side.php";  ?>
                        <div id="left">
                            <h1>Reservasi Kamar Hotel</h1>
                              
<form action="" method="post" enctype="multipart/form-data" name="input" id="form1" >

<table border="2" width="85%">
		<tr>
		<td colspan="3"><span style="font-size:16px; font-weight:bold;">Informasi Data diri</span></td>
		</tr>
		<tr>
		<td width="40%">Nama<br />
		<input type="text" name="nama" value="<? if($error){echo isset($_POST['nama']) ? $_POST['nama'] : '' ; } ?>" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;" />
		<div style="color:red"><? echo isset($error['nama']) ? $error['nama'] :''; ?></div>		</td>
		<td colspan="2"></td>
		<td>Jenis Kelamin <br />
		<input type="radio" value="L" name="jk"/>Laki-Laki&nbsp;&nbsp;<input type="radio" value="P" name="jk" />Perempuan</td><td></td>
		</tr>
		<tr>
		<td>Tempat Lahir<br />
		<input type="text" name="t_lahir" value="<? if($error){echo isset($_POST['t_lahir']) ? $_POST['t_lahir'] : '' ; } ?>" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;"  />
		<div style="color:red"><? echo isset($error['t_lahir']) ? $error['t_lahir'] :''; ?></div>		</td>
		<td colspan="2"></td>
		<td>Tgl Lahir<br />
		<select name="tgl" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;">
		<?php
					for ($i=1; $i<=31; $i++) {
						$tg = ($i<10) ? "0$i" : $i;
						echo "<option value='$tg'>$tg</option>";	
					}
				?>
        </select>
       -  
       <select name="bln" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;">
	   <?php
					for ($i=1; $i<=12; $i++) {
						$bl = ($i<10) ? "0$i" : $i;
						echo "<option value='$bl'>$bl</option>";	
					}
				?>
          </select>
        -
        <select name="thn" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;" >
		<?php
					for ($i=1970; $i<=2000; $i++) {
						echo "<option value='$i'>$i</option>";	
					}
				?>
          </select></td>
		<td></td>
		</tr>
		<tr height="30"><td></td></tr>		
		<tr height="30">
		<td colspan="3"><span style="font-size:16px; font-weight:bold;">Your Contac</span></td>
		</tr>
		</tr>
		<tr>
		<td>Alamat<br />
		<input type="text" name="alamat"  value="<? if($error){echo isset($_POST['alamat']) ? $_POST['alamat'] : '' ; } ?>" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;" />
		<div style="color:red"><? echo isset($error['alamat']) ? $error['alamat'] :''; ?></div>		</td>
		<td colspan="2"></td>
		<td>Kota<br />
		<input type="text" name="kota" value="<? if($error){echo isset($_POST['kota']) ? $_POST['kota'] : '' ; } ?>"  style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;"/>
		<div style="color:red"><? echo isset($error['kota']) ? $error['kota'] :''; ?></div>		</td>
		<td></td>
		</tr>
		<tr>
		<td>Email<br />
		<input type="text" name="email" <? if($error){echo isset($_POST['email']) ? $_POST['email'] : '' ; } ?>  style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;" />
		<div style="color:red"><? echo isset($error['email']) ? $error['email'] :''; ?><? echo isset($error['email1']) ? $error['email1'] : '' ; ?></div>		</td>
		<td width="30"></td>
		</tr>
		<tr>
		<td>Telp<br />
		<input type="text" name="telp" <? if($error){echo isset($_POST['telp']) ? $_POST['telp'] : '' ; } ?> style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;" />
		<div style="color:red"><? echo isset($error['telp']) ? $error['telp'] :''; ?></div>		</td>
		<td></td>
		</tr>
		<tr height="30"><td></td></tr>		
		<tr>
		<td colspan="3"><span style="font-size:16px; font-weight:bold;">Your Reservation</span></td>
		</tr>
		<td>Room Type<br />
		 <select name="roomid" id="roomid" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;"> 
        <option value="" >Select Room</option>
           <?  $sql=mysql_query("select * from j_kamar ");
		while($row=mysql_fetch_array($sql)){
		echo "<option value='$row[id_kamar]'>$row[nama]</option>";
		} ?>
         </select></td>
		<td></td>
		<tr>
		<td>Adult<br />
		<input type="text" name="adult"  value="<? if($error){echo isset($_POST['adult']) ? $_POST['adult'] : '' ; } ?>" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;"/>
		<div style="color:red"><? echo isset($error['adult']) ? $error['adult'] :''; ?></div>		</td>
		<td colspan="2"></td>
				<td>Children<br />
		<input type="text" name="children"  style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;"/> </td>
		<td></td>
		</tr>
		<tr>
			<td>Check In<br />
			 <select name="tgl1" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;">
		<?php
					for ($i=1; $i<=31; $i++) {
						$tg = ($i<10) ? "0$i" : $i;
						echo "<option value='$tg'>$tg</option>";	
					}
				?>
        </select>
       -  
       <select name="bln1" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;">
	   <?php
					for ($i=1; $i<=12; $i++) {
						$bl = ($i<10) ? "0$i" : $i;
						echo "<option value='$bl'>$bl</option>";	
					}
				?>
          </select>
        -
               <select name="thn1" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;">
		
            <option value="<?php echo date("Y"); ?>" selected="selected"><?php echo date("Y"); ?></option>
			</select> </td>
<td colspan="2"></td>		
  				<td>Check Out<br />
			<select name="tgl2" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;">
		<?php
					for ($i=1; $i<=31; $i++) {
						$tg = ($i<10) ? "0$i" : $i;
						echo "<option value='$tg'>$tg</option>";	
					}
				?>
        </select>
       -  
       <select name="bln2" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;">
	   <?php
					for ($i=1; $i<=12; $i++) {
						$bl = ($i<10) ? "0$i" : $i;
						echo "<option value='$bl'>$bl</option>";	
					}
				?>
          </select>
        -
        <select name="thn2" style="background:#FF9933; color: #000000; border: 2px ridge #7F4500;">
		
            <option value="<?php echo date("Y"); ?>" selected="selected"><?php echo date("Y"); ?></option>
			</select></td>
<td></td>		
		  </tr>
		  <tr>
		  		<td height="40" align="right" style="vertical-align:bottom"><input type="submit" name="input" value="Send" />&nbsp;&nbsp;<input type="reset" value="Reset" /></td>
		  </tr>
	</table>
</form>
							<div style=" height:10px"></div>
                        
                  </div>
                      <div style="clear: both; height: 10px"></div>
        		</div>
                <div class="cont_bot"></div>
    <!-- content ends -->
    <div style="height:10px;"></div>
   
<? include "footer.php";  ?>
</div>

</div>
</div>
</body>
</html>
Dan ini cek_kamar.php
<?php
//jangan lupa konek ke database
$konek=mysql_connect ("localhost","root","") or die ("koneksi gagal");
mysql_select_db("hotel2");
$idKamar = $_GET['id'];
$hs =  mysql_query("select * from j_kamar where id_kamar='".$idKamar."'");
$data = mysql_fetch_assoc($hs);
header("Content-Type: text/json");
echo json_encode($data);
?>
Maaf Mas sedikit menyusahkan..
Sukses Bwt Mas Ellyx..
0
Loading...
Ellyx Christian · Sep 17, 2012 · 0 Suka · 0 Tidak Suka
coba ganti javascriptnya dari:
<script type="text/javascript">
$(document).ready(function(){
	$('#roomid').change(function(){
		var idkamar = $(this).val();
		$.ajax({
			url:'cek_kamar.php?id='+idkamar,
			dataType:'json',
			success:function(hasil){
				var sisa = parseFloat(hasil.sisa);
				if(sisa <= 0){
					alert('Anda tidak bisa booking kamar ini');
					$(':submit').attr('disabled','disabled');
				}else{
					$(':submit').removeAttr('disabled');
				}
 
			}
		});
	});
});
menjadi
<script type="text/javascript">
$(document).ready(function(){
	$('#roomid').change(function(){
		var idkamar = $(this).val();
		$.ajax({
			url:'cek_kamar.php?id='+idkamar,
			dataType:'json',
			success:function(hasil){
				var sisa = parseFloat(hasil.sisa);
				if(sisa <= 0){
					alert('Anda tidak bisa booking kamar ini');
					$(':submit').attr('disabled','disabled');
				}else{
					$(':submit').removeAttr('disabled');
				}
 
			},
			error:function(){
				alert('terjadi error, silahkan coba lagi');
			}
		});
	});
});
0
Loading...
Ellyx Christian · Sep 17, 2012 · 0 Suka · 0 Tidak Suka
dan satu lagi kamu pake php versi berapa?
0
Loading...
Marini Stefani · Sep 17, 2012 · 0 Suka · 0 Tidak Suka
Sdh saya ganti Java Scriptnya MasEllyx Christian..Tp sama saja..
PHP saya versi 5.1.4
Ini Strukture Tabel saya Mas Ellyx..Kira2 karna ini ga??
-- phpMyAdmin SQL Dump
-- version 2.8.1
-- http://www.phpmyadmin.net
-- 
-- Host: localhost
-- Generation Time: Sep 18, 2012 at 12:20 AM
-- Server version: 5.0.21
-- PHP Version: 5.1.4
-- 
-- Database: `hotel2`
-- 

-- --------------------------------------------------------

-- 
-- Table structure for table `j_kamar`
-- 

CREATE TABLE `j_kamar` (
  `id_kamar` int(11) NOT NULL auto_increment,
  `nama` varchar(50) collate latin1_general_ci NOT NULL,
  `all` int(11) NOT NULL,
  `booking` int(11) NOT NULL,
  `sisa` int(11) NOT NULL,
  `price` int(20) NOT NULL,
  PRIMARY KEY  (`id_kamar`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=9 ;

-- 
-- Dumping data for table `j_kamar`
-- 

INSERT INTO `j_kamar` VALUES (1, 'Standard', 26, 0, 26, 440000);
INSERT INTO `j_kamar` VALUES (2, 'Superior', 39, 4, 35, 560000);
INSERT INTO `j_kamar` VALUES (3, 'Deluxe', 15, 16, -1, 660000);
INSERT INTO `j_kamar` VALUES (4, 'Resort Pool View', 20, 0, 20, 750000);
INSERT INTO `j_kamar` VALUES (5, 'Junior Suite', 8, 2, 6, 850000);
INSERT INTO `j_kamar` VALUES (6, 'Executive Suite', 1, 0, 1, 950000);
INSERT INTO `j_kamar` VALUES (7, 'Villa 1', 1, 2, -1, 1100000);
INSERT INTO `j_kamar` VALUES (8, 'Villa 2', 1, 0, 1, 1600000);

-- --------------------------------------------------------

-- 
-- Table structure for table `reservasi`
-- 

CREATE TABLE `reservasi` (
  `id` int(11) NOT NULL auto_increment,
  `id_kamar` int(11) NOT NULL,
  `nama` varchar(30) collate latin1_general_ci NOT NULL,
  `t_lahir` varchar(30) collate latin1_general_ci NOT NULL,
  `tgl_lahir` varchar(30) collate latin1_general_ci NOT NULL,
  `jk` enum('L','P') collate latin1_general_ci NOT NULL,
  `alamat` varchar(50) collate latin1_general_ci NOT NULL,
  `kota` varchar(30) collate latin1_general_ci NOT NULL,
  `email` varchar(30) collate latin1_general_ci NOT NULL,
  `telp` varchar(30) collate latin1_general_ci NOT NULL,
  `adult` int(11) NOT NULL,
  `children` int(11) NOT NULL,
  `check_in` varchar(30) collate latin1_general_ci NOT NULL,
  `check_out` varchar(30) collate latin1_general_ci NOT NULL,
  `lama` int(11) NOT NULL,
  `bill` int(11) NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=25 ;

-- 
-- Dumping data for table `reservasi`
-- 

INSERT INTO `reservasi` VALUES (5, 2, 'Anggun S', 'Pekan Baru', '19-09-1991', 'P', 'Jl.Beringin', 'Duri', 'Anggun@gmail.com', '(0765) 1155', 1, 2, '19-09-2012', '20-09-2012', 2, 1120000);
INSERT INTO `reservasi` VALUES (4, 2, 'Bangkit', 'Pekan Baru', '20-02-1982', 'L', 'Jl.Beringin', 'Duri', 'bangkit@localhost', '11', 1, 1, '04-10-2012', '09-10-2012', 6, 3360000);
INSERT INTO `reservasi` VALUES (6, 2, 'Ade', 'Duri', '16-06-1986', 'L', 'Jl.Sudirman', 'xxs', 'ade@ymail.com', '(0765) 1155', 3, 2, '10-10-2012', '10-10-2012', 1, 560000);
INSERT INTO `reservasi` VALUES (7, 2, 'setya td', 'Duri', '10-10-1970', 'L', 'Jl.Beringin', 'Dumai', 'setia@gmail.com', '11', 2, 2, '09-11-2012', '10-11-2012', 2, 1120000);
INSERT INTO `reservasi` VALUES (23, 3, 'welni', 'duri', '01-01-1970', 'P', 'jl.makmur', 'duri', 'welni@gmail.com', '345677', 2, 2, '01-01-2012', '02-01-2012', 2, 1320000);
INSERT INTO `reservasi` VALUES (24, 7, 'dadang', 'pekanbaru', '01-01-1970', 'L', 'jl.makmur', 'duri', 'dadang@gmail.com', '345677', 3, 2, '01-01-2012', '02-01-2012', 2, 2200000);
Terima Kasih Ellyx Christian..
0
Loading...
Marini Stefani · Sep 19, 2012 · 0 Suka · 0 Tidak Suka
Mas Ellyx Christian sdh saya coba2 ga bs juga..
Muncul Alert "terjadi error, silahkan coba lagi"
Dmna Slhnya Mas..???
Tolong Ya MAs Ellyx..
Terima kasih sblmnya..
0
Loading...
Ellyx Christian · Sep 19, 2012 · 0 Suka · 0 Tidak Suka
kamu pake php versi berapa? itu harus menggunakan php version 5.2 keatas