Click here to Skip to main content
14,927,655 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi frnds,
in this code when i click Confirm Choices the booked count should increase in db and if the user select booked img it should display room has been booked can u please help..

XML
<?php
mysql_connect("localhost","root","");
mysql_select_db("hotel");
error_reporting(E_ALL ^ E_NOTICE);
$notify = "";
$sql = "SELECT * FROM room";
$getquery = mysql_query($sql);
$submit=$_POST['submit'];
if($submit)
{
    if($booked)
    {
        $insert=mysql_query("INSERT INTO room (booked) VALUES ('$taken')");
        echo $insert;
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title>sample</title>
        <script type="text/javascript">
            numPremSeatsPerRow = 6;
            PremRowNames = ['A','B','C','D'];
            numCheapSeatsPerRow = 10;
            CheapRowNames = ['E','F','G','H','I'];
            statusPics = new Array();
            statusPics['avail'] = new Image();
            statusPics['mine'] = new Image();
            statusPics['taken'] = new Image();
            statusPics['vacate'] = new Image();
            statusPics['avail'].src = 'blue.jpg';
            statusPics['mine'].src = 'green.jpg';
            statusPics['taken'].src = 'red.jpg';
            statusPics['vacate'].src = 'blue1.jpg';
            function createSeats(oSeatsContainer,seatsPerRow,rowNames){
                var oRow = document.createElement('tr');
                oRow.appendChild(document.createElement('th'));
                for(i=1; i <= seatsPerRow; i++){
                    var oTh = document.createElement('th');
                    oTh.appendChild(document.createTextNode(i));
                    oRow.appendChild(oTh);
                }
                oSeatsContainer.appendChild(oRow); //this row contains the seat numbers
                for(i=0; i < rowNames.length; i++){
                    var oRow = document.createElement('tr');
                    var oCell = document.createElement('td');
                    oCell.innerHTML = rowNames[i];
                    oRow.appendChild(oCell);
                    for(j=0; j < seatsPerRow; j++){
                        oCell = document.createElement('td');
                        var oImg = document.createElement('img');
                        oImg.src = statusPics['avail'].src;
                        oImg.status = 'avail';
                        oImg.id = rowNames[i]+(j+1);
                        oImg.onclick=function(){
                            this.status = (this.status == 'avail')? 'mine' : 'avail';
                            this.src = (this.status == 'avail')? statusPics['avail'].src : statusPics['mine'].src;
                            oTotalprice.innerHTML = '';
                            oBookedSeatNos.innerHTML = '';

                        }
                        oCell.appendChild(oImg);
                        oRow.appendChild(oCell);
                    }
                    oSeatsContainer.appendChild(oRow);
                }
            }
            function confirmChoices(){
                premSeatsSelected = new Array();
                for(i=0; i < oPremSeats.length; i++){
                    if(oPremSeats[i].status == 'mine'){
                        premSeatsSelected.push(oPremSeats[i].id);
                        oPremSeats[i].src=statusPics['taken'].src
                    }
                    if(oPremSeats[i].status == 'taken'){
                        premSeatsSelected.push(oPremSeats[i].id);
                        oPremSeats[i].src=statusPics['vacate'].src
                    }
                }
                cheapSeatsSelected = new Array;
                for(i=0; i < oCheapSeats.length; i++){
                    if(oCheapSeats[i].status == 'mine'){
                        cheapSeatsSelected.push(oCheapSeats[i].id);
                        oCheapSeats[i].src=statusPics['taken'].src
                    }
                    if(oPremSeats[i].status == 'taken'){
                        premSeatsSelected.push(oPremSeats[i].id);
                        oPremSeats[i].src=statusPics['vacate'].src
                    }

                }

            }

            window.onload=function(){
                oTblPremium = document.getElementById('tblPremium');
                oTblCheap = document.getElementById('tblCheap');
                oPremSeats = oTblPremium.getElementsByTagName('img');
                oCheapSeats = oTblCheap.getElementsByTagName('img');
                oTotalprice = document.getElementById('totalprice');
                oBookedSeatNos = document.getElementById('bookedSeatNos');
                createSeats(oTblPremium,numPremSeatsPerRow,PremRowNames); //create premium seats
                createSeats(oTblCheap,numCheapSeatsPerRow,CheapRowNames); //create cheap seats
                document.getElementById('confirm').onclick=confirmChoices;
                document.getElementById('btnReset').onclick=function(){
                    oTotalprice.innerHTML = '';
                    oBookedSeatNos.innerHTML = '';
                    for(i=0; i < oPremSeats.length; i++){
                        oPremSeats[i].src = statusPics['avail'].src;
                        oPremSeats[i].status = 'avail';
                    }
                    for(i=0; i < oCheapSeats.length; i++){
                        oCheapSeats[i].src = statusPics['avail'].src;
                        oCheapSeats[i].status = 'avail';
                    }
                }
                document.getElementById('imgAvail').src = statusPics['avail'].src;
                document.getElementById('imgMine').src = statusPics['mine'].src;
                document.getElementById('imgTaken').src = statusPics['taken'].src;
                document.getElementById('imgvacate').src = statusPics['vacate'].src;
            }
        </script>
        <script language="javascript" type="text/javascript">
<!--
//Browser Support Code
function ajaxFunction(){
 var ajaxRequest;  // The variable that makes Ajax possible!

 try{
   // Opera 8.0+, Firefox, Safari
   ajaxRequest = new XMLHttpRequest();
 }catch (e){
   // Internet Explorer Browsers
   try{
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
   }catch (e) {
      try{
         ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      }catch (e){
         // Something went wrong
         alert("Your browser broke!");
         return false;
      }
   }
 }
 // Create a function that will receive data
 // sent from the server and will update
 // div section in the same page.
 ajaxRequest.onreadystatechange = function(){
   if(ajaxRequest.readyState == 4){
      var ajaxDisplay = document.getElementById('ajaxDiv');
      ajaxDisplay.innerHTML = ajaxRequest.responseText;
   }
 }
 // Now get the value from user and pass it to
 // server script.
 var age = document.getElementById('avilable').value;
 var wpm = document.getElementById('booked').value;
 var sex = document.getElementById('vacated').value;
 var queryString = "?avilable=" + avilable ;
 queryString +=  "&booked=" + wpm + "&vacated=" + sex;
 ajaxRequest.open("GET", "s2-ex.php" +
                              queryString, true);
 ajaxRequest.send(null);
}
//-->
</script>
        <style>
        .tab{
    margin-top:10px;

    border-radius: 7px;
    border: 2px solid #CCCCCC;


    margin-bottom:20px;
    }
body { margin: auto 48px; }

    </style>
    </head>
    <body>
    <form action="s2.php" method="POST">
        <div id="header"></div>
        <div id="wrapper">
            <div id="myTickets">
                <h1>hotel Room</h1>
                <div id="myTicket">
                    <h3>Your room Selection:</h3>
                </div>
                <div>
        <table>
            <thead>
                <tr>
                    <tr>Total</tr>
                    <tr>&nbsp;</tr>
                    <tr>Avilable</tr>
                    <tr>&nbsp;</tr>
                    <tr>Booked</tr>
                    <tr>&nbsp;</tr>
                    <tr>Vacated</tr>
                    <br>
                </tr>
            </thead>
            <tbody>
<?php
while($row = mysql_fetch_array($getquery)) {
echo '<br>';
    echo '<tr>' . $row['total'] .'</tr>';
    echo '<tr>' . '&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'</tr>';
    echo '<tr>' . $row['avilable'] .'&nbsp;'.'&nbsp;'.'</tr>';
    echo '<tr>' . '&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'</tr>';
    echo '<tr>' . $row['booked'] .'&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'</tr>';
    echo '<tr>' . '&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'&nbsp;'.'</tr>';
    echo '<tr>' . $row['vacated'] .'</tr>';
    echo '</table>';
}
?>
            </tbody>
        </table>
    </div>
                <div id="key">
                    <p>&nbsp;&nbsp;<img id="imgAvail" src="" alt="Available" /> = Available; <img id="imgMine" src="" alt="Mine" /> = Mine;
                        <img id="imgTaken" src="" alt="Taken" /> = Taken; <img id="imgvacate" src="" alt="vacate" /> = vacated;</p>
                </div>
            </div>
            <div id="seating">
                <h2 align="center">Raised Premium Rooms</h2>
                <table id="tblPremium" class="tab" bgcolor="#999999" cellspacing="4" align="center"></table>
                <h2 align="center">Regular Seats Rooms</h2>
                <table id="tblCheap" class="tab" bgcolor="#999999"  align="center"></table>
                <h5></h5>
                <div style="clear:both">
                </div>
                <br />
                <div id="theButtons">
                    <input type="button" value="Confirm Choices" id="confirm" />&nbsp;
                    <input type="submit" name="submit" value="book">&nbsp;
                    <input type="reset" id="btnReset" value="Reset" />

                </div>
            </div>
        </div>
        </form>
    </body>
</html>
Posted
Updated 2-Jan-14 20:22pm
v2
Comments
   
What have you tried and where is the problem?
Arun-23 3-Jan-14 3:17am
   
above code works but i need to store booked details in db how to do tat can u help me..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900