Jump to content

hotel reservation(get checkbox value and save to database)


champolot

Recommended Posts

please help me in my problem -_-...

 

first is it will show the room available and then the user will select a room(there are 3 rooms that can be reserve)...i want it can select more than 2 room....after that  reserve.php will show, it will show the room id and room type selected...
 

 

(continued the question below)

 

----this is my code in showing the datas from the database-----

ROOM.PHP

  <?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("shoopingcart", $con);
function formatMoney($number, $fractional=false) {
    if ($fractional) {
        $number = sprintf('%.2f', $number);
    }
    while (true) {
        $replaced = preg_replace('/(-?\d+)(\d\d\d)/', '$1,$2', $number);
        if ($replaced != $number) {
            $number = $replaced;
        } else {
            break;
        }
    }
    return $number;
}                
$result = mysql_query("SELECT * FROM room");

while($row = mysql_fetch_array($result))
  {
  $a=$row['room_id'];
  $query = mysql_query("SELECT sum(qty_reserve) FROM rooinventory where arrival <= '$arival' and departure >= '$departure' and room_id='$a'");
while($rows = mysql_fetch_array($query))
  {
  $inogbuwin=$rows['sum(qty_reserve)'];
  }
  $angavil = $row['qty'] - $inogbuwin;
 
  echo '<div style="height: 117px;">';
      echo '<div style="float: left; width: 100px; margin-left: 19px;">';
      echo "<img width=92 height=72 alt='Unable to View' src='" . $row["image"] . "'>";
      echo '</div>';
      echo '<div style="float: right; width: 575px; margin-top: -10px;">';
      echo '<span class="style5">'.'Avalable Rooms: '.$angavil.'</span>';
      if ($angavil > 0){
                    echo '<input name="roomid[]" type="checkbox" value="' .$row["room_id"]. '" />';
                    echo '<input type="submit" name="Submit" value="reserve" onclick="setDifference(this.form);"/>';
                    }
                if ($angavil <= 0){
                echo '<span class="style5">  '.'NO VACANT!'.'</span>';
                }    
      echo '<br>';        
      echo '<input name="typs" type="hidden" value="'.$row['type'].'"/>';
      
      echo '<span class="style5">'.'Room Type: '.$row['type'].'</span><br>';
      echo '<span class="style5">'.'Room Rate: '.$row['rate'].'</span><br>';
          
echo '<input name="avail" type="hidden" value="' .$angavil. '" />';
 
}

mysql_close($con);
?>
 
 </form>

 

there will be an array to show the datas from the checkbox...and the data from the checkbox will be put in the textbox...then ill save the data...if the user selected 2 rooms there will be a 2 data saved...there will be a 2 data saved so that i can search what are the available rooms to be reserve...

 

RESERVE.PHP

 <?php
        $checkBox = $_POST['roomid'];
        for($i=0; $i<sizeof($checkBox); $i++){
        echo $checkBox[$i];
        }
        
       if($checkBox[$i] == '1') {

$a=1;

}

if($checkBox[$i] == '2') {
b=1;

}

 

<input name="start" type=text value="<?php echo $checkBox[1] ?>"/>
        <input name="start" type=text value="<?php echo $checkBox[1] ?>"/>

 

so thats my question

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.