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 <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" /> <input type="reset" value="Reset" /></td>
</tr>
</table>
</form>
Maaf mas klu pertanyaan saya berbelit2,,
Sebelumnya terima Kasih Mas Ellyx Christian