Gotharious Posted September 1, 2011 Share Posted September 1, 2011 Hello there, I have a problem with this project I'm working on, everything is working fine except for one last thing. it goes as you go to the website, search for a city, choose a hotel from a list in that city, then book a room in that hotel, go to confirmation page then to paypal. everything is fine except after the booking when you go to the confirmation page, it shows correctly the number of nights you booked and everything, all except the rooms, it shows 0 rooms selected, and it doesn't give any price at all. here is the code <?php include("db.class.php"); class hotelManager { public function getHotel($where) { $where = isset($_POST['where']) ? $_POST['where'] : ""; $dbObj = new DB(); $where = $_POST['where']; $sql = "select * from hotels where city_id IN (select id from cities where name = '$where') or country_id IN (select id from countries where name = '$where')"; $result = mysql_query($sql); $arr = array(); echo "<table>"; while($row = mysql_fetch_array($result) or die(mysql_error())) { echo "<tr>"; echo "<td valign=\"top\" width=\"120px\">"; $rowid = $row['id']; $imageqry=mysql_query("SELECT * FROM `hotelphotos` where hotel_id='$rowid'"); $image=mysql_fetch_array($imageqry); $imagename=$image['attachmentName']; echo "<img src=\"foxmaincms/webroot/files/small/$imagename\"/>"; echo "</td>"; echo "<td valign=\"top\">"; echo "<table> <tr> <td valign=\"top\"> <a href=\"hotels.php?id=".$row['id']."\" class=\"titleslink\">".$row['name']."</a> </td> </tr> <tr> <td class=\"text\" valign=\"top\"> ".$row['location']." </td> </tr> </table>"; echo "</td>"; echo "</tr>"; } echo "</table>"; //return $arr; // array of arrays } /*************************** GET ONE HOTEL *****************************/ public function getHotelbyID($hotelID) { $dbObj = new DB(); $result = mysql_query("select * from hotels where id = '$hotelID'"); return $result; } public function HotelDatatabel($result) { $row = @mysql_fetch_array($result); echo "<table width=98%>"; echo "<tr>"; echo "<td valign=\"top\" width=\"120px\">"; $rowid = $row['id']; $imageqry=mysql_query("SELECT * FROM `hotelphotos` where hotel_id='$rowid' LIMIT 1"); $image=mysql_fetch_array($imageqry); $imagename=$image['attachmentName']; echo "<img src=\"foxmaincms/webroot/files/small/$imagename\"/>"; echo "</td>"; echo "<td valign=\"top\">"; echo "<table> <tr> <td valign=\"top\" class=\"searchtitle\"> ".$row['name']." </td> </tr> <tr> <td class=\"text\" valign=\"top\"> ".$row['location']." </td> </tr> <tr> <td> ".$row['details']." </td> </tr> <tr> <td> <a href=\"http://".$row['website']."\" class=\"link\">".$row['website']."</a> </td> </tr> </table>"; echo "</td>"; echo "</tr>"; echo "</table>"; } /************************************ GET ROOMS **************************************/ public function getHotelRooms($hotelID) { $result = mysql_query("select * from rooms where hotel_id = '$hotelID'"); echo "<form name='bookingform' id='bookingform' method='post' action='book.php'>"; echo "<input name=\"roomid\" id=\"roomid\" type=\"hidden\" />"; echo "<input name=\"roomnum\" id=\"roomnum\" type=\"hidden\" />"; echo "<input name=\"hotelid\" id=\"hotelid\" type=\"hidden\" value=\"$hotelID\"/>"; echo "<table width=80% >"; echo"<tr>"; echo "<td>Check-in date</td>"; echo "<td>"; echo "<input type=\"text\" name=\"datein\" class=\"date_input\" />"; echo "</td>"; echo "<td>Check-out date</td>"; echo "<td>"; echo "<input type=\"text\" name=\"dateout\" class=\"date_input\" />"; echo "</td>"; echo"</tr>"; echo "<table>"; echo "<table class=\"rooms\" width=100% cellspacing=\"1\" >"; echo "<tr> <th class=\"rooms\">Room Type</th> <th class=\"rooms\">Rate for night</th> <th class=\"rooms\">MAX</th> <th class=\"rooms\">Nr.rooms</th> <th class=\"rooms\">Book</th> </tr>"; while($row = @mysql_fetch_array($result)) { echo "<tr>"; echo "<td class=\"text\" align=center>".$row['room_type']."</td>"; echo "<td class=\"text\" align=center>".$row['price_per_day']."</td>"; echo "<td class=\"text\" align=center>".$row['people']." People</td>"; echo "<td class=\"text\" align=center>"; ?> <select name="nrooms" id="nrooms" onchange=" //alert('<?php echo $row['id'] ; ?>'); //alert(this.value); var exist = 0; if(roomids.length > 0) { for(var hh = 0;hh < roomids.length; hh++) { if(roomids[hh] == <?php echo $row['id'] ; ?>) { exist = 1; //alert(hh); roomnumar[hh] = this.value; } } if(exist == 0) { roomids.push(<?php echo $row['id'] ; ?>); roomnumar.push(this.value); } } else { roomids.push(<?php echo $row['id'] ; ?>); roomnumar.push(this.value); } document.bookingform.roomid.value = roomids; document.bookingform.roomnum.value = roomnumar; "> <option value=0> 0 </option> <?php for($i = 0; $i < $row['available_rooms']; $i++) { $nr = $i+1; $pr=$nr * $row['price_per_day']; echo "<option value=$nr>$nr ($pr\$)</option>"; } echo "</select> </td>"; echo "<td align=center> </td>"; echo "</tr>"; echo "<tr> <td> </td> <td> </td> <td> </td> <td> </td> </tr>"; } echo "<tr class=\"rooms\"> <td colspan=\"4\"> </td> <td align=center><input type=\"submit\" value=\"book\" id=\"bookroom\" name=\"bookroom\"/></td> </tr>"; echo "</table>"; echo "</form>"; print_r($_SESSION['order']); $_SESSION['order']=0; unset($_SESSION['order']); } } ?> BookinManager.php <?php include("hotelsManager.php"); ?> <?php include("config.php"); ?> <?php include("textManager.php"); ?> <?php function echoPostedData() { $dbo = new DB(); $hotelObj = new hotelManager(); $hotelID = $_POST['hotelid']; $datein = $_POST['datein']; $dateout = $_POST['dateout']; $roomid = $_POST['roomid']; $pr = $_POST['pr']; $_SESSION['hotelID'] = isset($_POST['hotelid']) ? $_POST['hotelid'] : $_SESSION['hotelID']; $_SESSION['datein'] = isset($_POST['datein']) ? $_POST['datein'] : $_SESSION['datein']; $_SESSION['dateout'] = isset($_POST['dateout']) ? $_POST['dateout'] : $_SESSION['dateout']; $_SESSION['roomid'] = isset($_POST['roomid']) ? $_POST['roomid'] : $_SESSION['roomid']; $roomsarray = explode(",",$_POST['roomid']); $_SESSION['roomsarray'] = isset($_POST['roomid']) ? explode(",",$_POST['roomid']) : $_SESSION['roomsarray']; $roonsNo = $_POST['nrooms']; $_SESSION['nrooms'] = isset($_POST['roomnum']) ? explode(",",$_POST['roomnum']) : $_SESSION['nrooms']; /********************** hotels ************************/ /******************************************************/ echo "<table width=95% border=0 align=\"center\" cellpadding=\"0\" cellspacing=\"0\"> <tr><td valign=\"top\">"; echo "<table>"; echo "<tr>"; echo "<td valign=top>"; $imageqry=mysql_query("SELECT * FROM `hotelphotos` where hotel_id='".$_SESSION['hotelID']."' LIMIT 1"); $image=mysql_fetch_array($imageqry); $imagename=$image['attachmentName']; echo "<img src=\"foxmaincms/webroot/files/small/$imagename\"/>"; echo "</td>"; echo "<td>"; $result=$hotelObj->getHotelbyID($_SESSION['hotelID']); $row = mysql_fetch_array($result); echo "<table>"; echo "<tr><td valign=top><strong class=subtitle3>".$row['name']."</strong></td></tr>"; echo "<tr><td class=text valign=top>".$row['location']."</td></tr>"; echo "<tr><td class=text valign=top>check-in Date: ".$_SESSION['datein']."</td></tr>"; echo "<tr><td class=text valign=top>check-out Date: ".$_SESSION['dateout']."</td></tr>"; echo "<tr><td class=text valign=top>"; $newdate = $_SESSION['dateout'] - $_SESSION['datein']; $totalprice = array_sum($_SESSION['totalprice']) echo "</td></tr>"; echo "<tr><td class=text valign=top>Total Price: ".$totalprice."</td></tr>"; echo "</table>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</td></tr></table>"; } function echoForm2() { ?> <form id="userDetails" name="userDetails" action="" method="post"> <table width="95%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td valign="top" class="subtitle3"><strong>Your Name</strong><br /> <input type="text" name="name" size="50" /></td> </tr> <tr> <td valign="top" class="subtitle3"><strong>Email address</strong><br /> <input type="text" name="email" size="50" /> </td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td valign="top" class="subtitle3"> <?php $roomsarray = explode(",",$_POST['roomid']); $roonsNo = explode(",",$_POST['roomnum']); for($i = 0;$i<count($roomsarray);$i++) { if($roonsNo[$i] > 1) { for($j = 0;$j<$roonsNo[$i];$j++) { echo "<div>"; $result = mysql_query("select * from rooms where id = '$roomsarray[$i]'"); $row = mysql_fetch_array($result); echo "<span class=subtitle3><strong>Room: </strong>".$row['room_type']." #".($j+1)."</span>"; echo "</div>"; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<span class=subtitle3><strong> Full guest name </strong></span>"; echo "<br />"; echo "<input type=text name=\"guest_name[]\" size=30/>"; echo "</td>"; echo "<td align=center> <span class=subtitle3><strong> Max people</strong></span> <br /> <span class=subtitle3>".$row['people']."guests</span> </td>"; echo "<td align=center> <span class=subtitle3><strong>Smoking</strong></span><br /> <select name='smoking'> <option value=\"\">...</option> <option value=\"yes\">Yes</option> <option value=\"no\">No</option> </select> </td>"; echo "</tr>"; echo "</table>"; echo "<br />"; } } else { if($roonsNo[$i] != 0) { echo "<div>"; $result = mysql_query("select * from rooms where id = '$roomsarray[$i]'"); $row = mysql_fetch_array($result); echo "<span class=subtitle3><strong>Room: </strong>".$row['room_type']."</span>"; echo "</div>"; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<span class=subtitle3><strong> Full guest name</strong></span>"; echo "<br />"; echo "<input type=text name=\"guest_name[]\" size=30/>"; echo "</td>"; echo "<td align=center> <span class=subtitle3><strong> Max people</strong></span> <br /> <span class=subtitle3>".$row['people']."guests</span> </td>"; echo "<td align=center> <span class=subtitle3><strong>Smoking</strong></span><br /> <select name='smoking'> <option value=\"\">...</option> <option value=\"yes\">Yes</option> <option value=\"no\">No</option> </select> </td>"; echo "</tr>"; echo "</table>"; echo "<br />"; } } } ?> <hr> </td> </tr> <tr> <td align="right"> <input type="submit" name="submit" id="submit" value="Make the reservation" /> </td> </tr> </table> </form> <?php } ?> <?php include("includes/bookinManager.php"); ?> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="formtable"> <tr> <th align="left" valign="top" class="formtable"> Booking Data </th> </tr> <tr> <td valign="top"> </td> </tr> <tr> <td valign="top"> <?php echoPostedData(); ?> </td> </tr> <tr> <td valign="top"> </td> </tr> </table> </td> </tr> <tr> <td valign="top"><img src="images/spacer.gif" width="28" height="10" /></td> </tr> <tr> <td valign="top"> <?php if(isset($_POST['bookroom'])) {?> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="formtable"> <tr> <th align="left" valign="top" class="formtable"> Your Details </th> </tr> <tr> <td valign="top" > <form action="book.php" method="post" id="payPalForm"> <table width="60%" border="0" cellpadding="0" cellspacing="0" class="formtable"> <tr> <td>First name :</td> <td><input type="text" name="first_name" /></td> </tr> <tr> <td>Last name :</td> <td><input type="text" name="last_name" /></td> </tr> <tr> <td>Email address :</td> <td><input type="text" name="email" /></td> </tr> <tr> <td>Full guest name :</td> <td><input type="text" name="full" /></td> </tr> <tr> <td>Address :</td> <td><INPUT type="text" NAME="address1" VALUE=""/></td> </tr> <tr> <td>Special Requests :</td> <td><input type="text" name="special" /></td> </tr> </table> </td> </tr> <tr> <td valign="top"> <?php //echoForm2(); ?> <input type="hidden" name="item_number" value="<?php echo $row['id']; ?>"> <input type="hidden" name="cmd" value="_ext-enter"> <input type="hidden" name="redirect_cmd" value="_xclick"> <input type="hidden" name="business" value="tarek_1305896294_biz@gotharious.com"> <input type="hidden" name="item_name" value="Standard Room: Dar El Masyaf Hotel : 2 nights : 9th, july, 2011"> <input type="hidden" name="currency_code" value="USD"> <INPUT TYPE="hidden" NAME="first_name" VALUE="Tarek"> <INPUT TYPE="hidden" NAME="last_name" VALUE="Sabrouty"> <INPUT TYPE="hidden" NAME="address1" VALUE="9th Popastes St."> <INPUT TYPE="hidden" NAME="address2" VALUE="Cleopatra Hamamat"> <INPUT TYPE="hidden" NAME="city" VALUE="Alexandria"> <INPUT TYPE="hidden" NAME="Country" VALUE="Egypt"> <INPUT TYPE="hidden" NAME="lc" VALUE="US"> <INPUT TYPE="hidden" NAME="email" VALUE="tarek@gotharious.com"> <INPUT TYPE="hidden" NAME="night_phone_a" VALUE="+20166005733"> <INPUT TYPE="hidden" NAME="amount" VALUE="100.00"> <?php $roomsarray = explode(",",$_POST['roomid']); $roonsNo = explode(",",$_POST['roomnum']); for($i = 0;$i<count($roomsarray);$i++) { if($roonsNo[$i] > 1) { for($j = 0;$j<$roonsNo[$i];$j++) { echo "<div>"; $result = mysql_query("select * from rooms where id = '$roomsarray[$i]'"); $row = mysql_fetch_array($result); echo "<span class=subtitle3><strong>Room: </strong>".$row['room_type']." #".($j+1)."</span>"; echo "</div>"; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<span class=subtitle3><strong> Full guest name </strong></span>"; echo "<br />"; echo "<input type=text name=\"guest_name[]\" size=30/>"; echo "</td>"; echo "<td align=center> <span class=subtitle3><strong> Max people</strong></span> <br /> <span class=subtitle3>".$row['people']."guests</span> </td>"; echo "<td align=center> <span class=subtitle3><strong>Smoking</strong></span><br /> <select name='smoking'> <option value=\"\">...</option> <option value=\"yes\">Yes</option> <option value=\"no\">No</option> </select> </td>"; echo "</tr>"; echo "</table>"; echo "<br />"; } } else { if($roonsNo[$i] != 0) { echo "<div>"; $result = mysql_query("select * from rooms where id = '$roomsarray[$i]'"); $row = mysql_fetch_array($result); echo "<span class=subtitle3><strong>Room: </strong>".$row['room_type']."</span>"; echo "</div>"; echo "<table>"; echo "<tr>"; echo "<td>"; echo "<span class=subtitle3><strong> Full guest name</strong></span>"; echo "<br />"; echo "<input type=text name=\"guest_name[]\" size=30/>"; echo "</td>"; echo "<td align=center> <span class=subtitle3><strong> Max people</strong></span> <br /> <span class=subtitle3>".$row['people']."guests</span> </td>"; echo "<td align=center> <span class=subtitle3><strong>Smoking</strong></span><br /> <select name='smoking'> <option value=\"\">...</option> <option value=\"yes\">Yes</option> <option value=\"no\">No</option> </select> </td>"; echo "</tr>"; echo "</table>"; echo "<br />"; } } } ?> <input type="submit" name="Submit" value="Submit"> </form> <tr> <td valign="top"> </td> </tr> </table> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/246154-booking-hotel-room-error-when-performing-echo-posted-data/ Share on other sites More sharing options...
the182guy Posted September 1, 2011 Share Posted September 1, 2011 Are you getting any errors? Have you tried putting some die() or echo's in throughout to see where the problem begins? Quote Link to comment https://forums.phpfreaks.com/topic/246154-booking-hotel-room-error-when-performing-echo-posted-data/#findComment-1264212 Share on other sites More sharing options...
Gotharious Posted September 1, 2011 Author Share Posted September 1, 2011 No, Actually I'm not getting any errors at all, just gives me 0 number of rooms booked but the right number of nights Quote Link to comment https://forums.phpfreaks.com/topic/246154-booking-hotel-room-error-when-performing-echo-posted-data/#findComment-1264371 Share on other sites More sharing options...
PFMaBiSmAd Posted September 1, 2011 Share Posted September 1, 2011 Could you at least identify the variable name that should contain the correct value and the place where it is being echoed out in the code you posted? You have posted several hundred lines of code that we have no way of running (we don't have your database tables and aren't likely to create them and put test data into them) and want someone to figure out why you are getting a zero at some unidentified point in it. Quote Link to comment https://forums.phpfreaks.com/topic/246154-booking-hotel-room-error-when-performing-echo-posted-data/#findComment-1264373 Share on other sites More sharing options...
Gotharious Posted September 1, 2011 Author Share Posted September 1, 2011 Ok, here are the variables here is to choose the rooms </tr>"; while($row = @mysql_fetch_array($result)) { echo "<tr>"; echo "<td class=\"text\" align=center>".$row['room_type']."</td>"; echo "<td class=\"text\" align=center>".$row['price_per_day']."</td>"; echo "<td class=\"text\" align=center>".$row['people']." People</td>"; echo "<td class=\"text\" align=center>"; ?> <select name="nrooms" id="nrooms" onchange=" //alert('<?php echo $row['id'] ; ?>'); //alert(this.value); var exist = 0; if(roomids.length > 0) { for(var hh = 0;hh < roomids.length; hh++) { if(roomids[hh] == <?php echo $row['id'] ; ?>) { exist = 1; //alert(hh); roomnumar[hh] = this.value; } } if(exist == 0) { roomids.push(<?php echo $row['id'] ; ?>); roomnumar.push(this.value); } } else { roomids.push(<?php echo $row['id'] ; ?>); roomnumar.push(this.value); } document.bookingform.roomid.value = roomids; document.bookingform.roomnum.value = roomnumar; "> <option value=0> 0 </option> <?php for($i = 0; $i < $row['available_rooms']; $i++) { $nr = $i+1; $pr=$nr * $row['price_per_day']; echo "<option value=$nr>$nr ($pr\$)</option>"; } and here is the echo function <?php function echoPostedData() { $dbo = new DB(); $hotelObj = new hotelManager(); $hotelID = $_POST['hotelid']; $datein = $_POST['datein']; $dateout = $_POST['dateout']; $roomid = $_POST['roomid']; $pr = $_POST['pr']; $_SESSION['hotelID'] = isset($_POST['hotelid']) ? $_POST['hotelid'] : $_SESSION['hotelID']; $_SESSION['datein'] = isset($_POST['datein']) ? $_POST['datein'] : $_SESSION['datein']; $_SESSION['dateout'] = isset($_POST['dateout']) ? $_POST['dateout'] : $_SESSION['dateout']; $_SESSION['roomid'] = isset($_POST['roomid']) ? $_POST['roomid'] : $_SESSION['roomid']; $roomsarray = explode(",",$_POST['roomid']); $_SESSION['roomsarray'] = isset($_POST['roomid']) ? explode(",",$_POST['roomid']) : $_SESSION['roomsarray']; $roonsNo = $_POST['nrooms']; $_SESSION['nrooms'] = isset($_POST['roomnum']) ? explode(",",$_POST['roomnum']) : $_SESSION['nrooms']; and here is where it should be posted <?php include("includes/bookinManager.php"); ?> <table width="100%" border="0" cellpadding="0" cellspacing="0" class="formtable"> <tr> <th align="left" valign="top" class="formtable"> Booking Data </th> </tr> <tr> <td valign="top"> </td> </tr> <tr> <td valign="top"> <?php echoPostedData(); ?> </td> </tr> <tr> <td valign="top"> </td> </tr> </table> </td> </tr> <tr> <td valign="top"><img src="images/spacer.gif" width="28" height="10" /></td> </tr> <tr> <td valign="top"> <?php if(isset($_POST['bookroom'])) {?> Quote Link to comment https://forums.phpfreaks.com/topic/246154-booking-hotel-room-error-when-performing-echo-posted-data/#findComment-1264431 Share on other sites More sharing options...
Gotharious Posted September 1, 2011 Author Share Posted September 1, 2011 Ok, I might have got to where is the problem now, but can't fix it when I book a room, and choose the dates, it gives me the right number of nights but zero rooms. I've tried different ways to make the number of rooms appear but still can't. The problem is that the variables for the rooms is not defined in the bookingmanager file, but in the hotels manager file, it gets the right data from the database. what I was to do now is when I book the room, it takes me to a confirmation page where it posts the data as HTML so it can take me to paypal website to make the payment Quote Link to comment https://forums.phpfreaks.com/topic/246154-booking-hotel-room-error-when-performing-echo-posted-data/#findComment-1264470 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.