如果选择,则在db中存储值 [英] storing values in db if selected

查看:56
本文介绍了如果选择,则在db中存储值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨frnds,

在此代码中,当我点击确认选择时,预订的计数应该在db中增加,如果用户选择预订的img它应该显示房间已被预订,请你帮忙..



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..

<?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>

推荐答案

notify = \"\";

notify = "";


sql = \"SELECT * FROM room\";

sql = "SELECT * FROM room";


getq uery = mysql_query(
getquery = mysql_query(


这篇关于如果选择,则在db中存储值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆