Gotharious Posted September 28, 2011 Author Share Posted September 28, 2011 ??? Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1273648 Share on other sites More sharing options...
Zane Posted September 28, 2011 Share Posted September 28, 2011 Ok, I'm lost. Reading the first page I had initially figured the problem was because of the intermittent javascript ... without now that jcbones has spoke up about it.. I'm lost on the status of your problem. Show us what is and is not coming through.. just as you did earlier. If you're just looking for a quick fix and want to send $pr real quick like, then change your form action to book.php?pr=$pr But I don't recommend that solution. Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1273654 Share on other sites More sharing options...
Gotharious Posted September 28, 2011 Author Share Posted September 28, 2011 Thanks, Zane Here is the problem.. in the confirmation page, it should show the total price for the reservation the client made, and then he confirms and get directed to paypal to make the payment But the problem is, I can't show the total price because the I can't get the Room ID to be passed the confirmation page, nor I can get the option he selected ($pr) which has the total price for one night. my Idea now is to either pass the Room ID or the price per day for it 1. If I get the room ID I'll make an sql query to get the price per day for this room and multiply it by the number of rooms and number of nights 2. If I get the $pr to be passed, then I will just multiply it with the number of nights and it would be working All the variables gets passed from the reservation page to the confirmation page, like hotel ID, date in and out, number of rooms, everything is great except for the Room ID (Which is the most important variable because the next step is Paying at Paypal) Here is the reservation form 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\" value=\"$roomID\"/>"; 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\" value=\"$datein\" />"; echo "</td>"; echo "<td>Check-out date</td>"; echo "<td>"; echo "<input type=\"text\" name=\"dateout\" class=\"date_input\" value=\"$dateout\" />"; 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['id']." room id</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>"; $price = $pr; } echo "</select> </td>"; echo "<td align=center>" .$row['id']." Room ID </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>"; and now the confirmation page function echoPostedData() { $dbo = new DB(); $hotelObj = new hotelManager(); $hotelID = $_POST['hotelid']; $roomID = $_POST['roomsid']; $roonsNo = $_POST['roomsNo']; $priced = $_POST['price']; $nr = $_POST['nr']; $_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['roomsid']) ? $_POST['roomsid'] : $_SESSION['roomID']; $_SESSION['nrooms'] = $_POST['nrooms']; $roomsarray = explode(",",$_POST['roomid']); $_SESSION['roomsarray'] = isset($_POST['roomsid']) ? explode(",",$_POST['roomsid']) : $_SESSION['roomsarray']; $roonsNo = $_POST['nrooms']; $_SESSION['nrooms'] = isset($_POST['roomnum']) ? explode(",",$_POST['roomnum']) : $_SESSION['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>"; $dateout = explode(' ',$_SESSION['dateout']); $datein = explode(' ',$_SESSION['datein']); $newdate = (int)(strtotime($dateout[1] . '-' . $dateout[0] . '-' . $dateout[2] ) - strtotime($datein[1] . '-' . $datein[0] . '-' . $datein[2])) / 86400; $totalprice = $roonsNo * $newdate ; echo "</td></tr>"; echo "<tr><td class=text valign=top>Total Price: ".$totalprice."</td></tr>"; echo "<tr><td class=text valign=top>Total Nights: ".$newdate."</td></tr>"; echo "</table>"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</td></tr></table>"; Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1273665 Share on other sites More sharing options...
Gotharious Posted September 28, 2011 Author Share Posted September 28, 2011 Oh and I tried changing form action to book.php?pr=$pr and also for Room ID, but they all give empty result Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1273669 Share on other sites More sharing options...
Zane Posted September 28, 2011 Share Posted September 28, 2011 if you use ?pr=$pr, then the variable will not show up in the $_POST array. Instead it will be in the $_GET array. Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1273672 Share on other sites More sharing options...
Zane Posted September 28, 2011 Share Posted September 28, 2011 Also, you still have javascript inside a PHP while loop. Not to mention, the javascript isn't even within script tags, so I don't understand how you're NOT getting an error. Put the following at the very beginning of your script error_reporting(E_ALL); ini_set('display_errors', true); ?> Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1273677 Share on other sites More sharing options...
Gotharious Posted September 28, 2011 Author Share Posted September 28, 2011 Tried that, still nothing No errors giving also after putting your code Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1273691 Share on other sites More sharing options...
jcbones Posted September 28, 2011 Share Posted September 28, 2011 Open up the firefox error console, and see what the javascript errors are. Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1273716 Share on other sites More sharing options...
Gotharious Posted September 28, 2011 Author Share Posted September 28, 2011 only one error found and that was it Warning: Expected declaration but found '/'. Skipped to next declaration. Source File: images/styles.css Line: 371 Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1273726 Share on other sites More sharing options...
Gotharious Posted September 29, 2011 Author Share Posted September 29, 2011 I tried putting this code in the while loop, not even sure if it's right or now, but I'm just trying anything until hopefully I can get it to work while($row = @mysql_fetch_array($result)) { $roomID = $row['id']; 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>".$roomID." room id</td>"; echo "<td class=\"text\" align=center>"; ?> <select name="nrooms" id="nrooms" onchange=""> //alert('<?php echo $row['id'] ; ?>'); //alert(this.value); <?php error_reporting(E_ALL); ini_set('display_errors', true); ?> 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>"; $price = $roomID; Btw, when I echo $row['id'] in the reservation form, it echos the correct room ID of it but I still can't pass it to the confirmation page Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274064 Share on other sites More sharing options...
Gotharious Posted September 30, 2011 Author Share Posted September 30, 2011 Ok, I think all is needed is to pass the $row['id'] from the reservation page to the confirmation page, that's all but I can't really do that, anyone? Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274488 Share on other sites More sharing options...
Buddski Posted September 30, 2011 Share Posted September 30, 2011 Could the problem possibly be that you arent passing $roomID into the getHotelRooms function? 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\" value=\"$roomID\"/>"; echo "<input name=\"roomnum\" id=\"roomnum\" type=\"hidden\">"; Nowhere in that function do i see a reference to the $roomID variable.. Hang on.. then you are loading another roomId in the while loop?! Ok.. so a HOTEL has many rooms, each of these rooms have a roomID.. Inside your while loop, you need to add a hidden field which stores roomID.. not at the top of the function. Unless you want to overwrite your $_POST data, your roomID field and the nrooms should be a HTML array. while($row = @mysql_fetch_array($result)) { $roomID = $row['id']; 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><input type=\"hidden\" name=\"roomID[$roomID]\" value=\"$roomID\" />$roomID room id</td>"; echo "<td class=\"text\" align=center> <select name=\"nrooms[$roomID]\" id=\"nrooms\" onchange=\"\">....... Then on your post, you can do this foreach ($_POST['roomID'] as $value) { echo 'For RoomID ' , $value , ' the person booked ' , $_POST['nrooms'][$value]; } Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274492 Share on other sites More sharing options...
Gotharious Posted October 1, 2011 Author Share Posted October 1, 2011 Well, It gives me Array now when I echo roomID Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274666 Share on other sites More sharing options...
Buddski Posted October 1, 2011 Share Posted October 1, 2011 That array will contain all the rooms for that hotelID, its upto you to find out which one the user wanted. Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274671 Share on other sites More sharing options...
Gotharious Posted October 1, 2011 Author Share Posted October 1, 2011 Ok good, but still I can't solve the problem now, I'm not sure what should I do next Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274677 Share on other sites More sharing options...
Gotharious Posted October 2, 2011 Author Share Posted October 2, 2011 any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274949 Share on other sites More sharing options...
Buddski Posted October 2, 2011 Share Posted October 2, 2011 So you are passing the roomIDs across, you have to figure out which one the user wanted. As per the example I already posted foreach ($_POST['roomID'] as $value) { echo 'For RoomID ' , $value , ' the person booked ' , $_POST['nrooms'][$value]; } That will show you how many of that room (for each room) a person booked, clearly, if the $_POST['nrooms'][$value] is 0 they dont want that room. Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274953 Share on other sites More sharing options...
Gotharious Posted October 2, 2011 Author Share Posted October 2, 2011 Ok, maybe I'm a bit mixed up now So this foreach, I should post it in the confirmation page, right? Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274958 Share on other sites More sharing options...
Buddski Posted October 2, 2011 Share Posted October 2, 2011 This is your code, but I guess so.. You should know what needs to happen at each stage of the booking process. Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274960 Share on other sites More sharing options...
Gotharious Posted October 2, 2011 Author Share Posted October 2, 2011 Ok, here is the outcome I got For RoomID 4 the person booked For RoomID 5 the person booked For RoomID 6 the person booked Dar Al Masyaf Hotel Jumeirah, in Jumeirah Beach Road check-in Date: 3 Oct 2011 check-out Date: 7 Oct 2011 Total Price: 12 Total Nights: 4 Total Rooms: Total Rooms: room id: Rooms id: Array Array ( [roomid] => [roomnum] => [hotelid] => 13 [datein] => 3 Oct 2011 [dateout] => 7 Oct 2011 [roomID] => Array ( [4] => 4 [5] => 5 [6] => 6 ) [nrooms] => 3 [bookroom] => book ) Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274963 Share on other sites More sharing options...
Buddski Posted October 2, 2011 Share Posted October 2, 2011 Each roomID should have it own nrooms like I posted previously.. You need an array to do this as I already pointed out. <select name=\"nrooms[$roomID]\" id=\"nrooms\" onchange=\"\"> This will tell you the nrooms for each roomID posted. Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274965 Share on other sites More sharing options...
Gotharious Posted October 2, 2011 Author Share Posted October 2, 2011 Ok, now it posts the roomID but not the selected one, because I selected room that has ID 6 and the outcome was 4, Also, it doesn't echo it here when I echo $roomID and the nrooms now gives an array instead of the number of rooms check-in Date: 17 Oct 2011 check-out Date: 20 Oct 2011 Total Price: 0 Total Nights: 3 Total Rooms: Total Rooms: room id: Rooms id: Array Array ( [roomid] => [roomnum] => [hotelid] => 13 [datein] => 17 Oct 2011 [dateout] => 20 Oct 2011 [roomID] => Array ( [4] => 4 [5] => 5 [6] => 6 ) [\"nrooms] => Array ( [$roomID] => 4 ) [bookroom] => book ) Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274985 Share on other sites More sharing options...
Buddski Posted October 2, 2011 Share Posted October 2, 2011 Your code must be incorrect. The $roomID SHOULD evalutate to the roomID in the HTML form, that 4 you are seeing is the value from the select box. [\"nrooms] => Array ( [$roomID] => 4 ) Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274987 Share on other sites More sharing options...
Gotharious Posted October 2, 2011 Author Share Posted October 2, 2011 I don't thing I'm following what you're saying... Sorry, I know I'm annoying sometimes, but I really don't get anything from what you said Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274992 Share on other sites More sharing options...
Buddski Posted October 2, 2011 Share Posted October 2, 2011 Ok, ill bring this code back.. while($row = @mysql_fetch_array($result)) { $roomID = $row['id']; 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><input type=\"hidden\" name=\"roomID[$roomID]\" value=\"$roomID\" />$roomID room id</td>"; echo "<td class=\"text\" align=center> <select name=\"nrooms[$roomID]\" id=\"nrooms\" onchange=\"\">....... In the select field $roomID should evaluate to whatever is stored in $row['id']; From what your code says, it is not. Once you find out why the post will be a different story. It should give you this as a result. Array ( [roomid] => [roomnum] => [hotelid] => 13 [datein] => 17 Oct 2011 [dateout] => 20 Oct 2011 [roomID] => Array ( [4] => 4 [5] => 5 [6] => 6 ) [nrooms] => Array ( [4] => 0 // RoomID 4 had no selections // [5] => 0 // RoomID 5 had no selections // [6] => 4 // RoomID 6 had 4 selected // ) [bookroom] => book ) Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/page/2/#findComment-1274995 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.