Gotharious Posted September 25, 2011 Share Posted September 25, 2011 Hey all, I have this problem, in a hotel booking system, i got everything right except in the confirmation page before you get directed to Paypal The problem is it doesn't post the room ID in the confirmation page, it posts everything right except for the room ID it's blank and because of that It doesn't show the price here is the code function echoPostedData() { $dbo = new DB(); $hotelObj = new hotelManager(); $hotelID = $_POST['hotelid']; $roomid = $_POST['roomid']; $roonsNo = $_POST['roomsNo']; $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']; $_SESSION['nrooms'] = $_POST['nrooms']; $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']; Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/ Share on other sites More sharing options...
AyKay47 Posted September 25, 2011 Share Posted September 25, 2011 judging from your code, the only thing that would be causing this is your roomid POST data not being set.. your logic seems a little off here.. why would you set the session variable to itself if the POST data is not set.. I would check that all necessary data is filled... if it is, set the session variables.. if its not, trigger some sort of error.. having an empty session variable won't so you much good, as you can see. Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272588 Share on other sites More sharing options...
Gotharious Posted September 25, 2011 Author Share Posted September 25, 2011 Thanks, mate for your help but I'm sorry I didn't get anything of what you said, I'm a newbie as you see I don't understand what you mean by roomid POST data not being set.. how should I set it? Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272591 Share on other sites More sharing options...
AyKay47 Posted September 25, 2011 Share Posted September 25, 2011 that value is coming from a form right.. so you tell me how its being set..perhaps post the form code Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272592 Share on other sites More sharing options...
Gotharious Posted September 25, 2011 Author Share Posted September 25, 2011 here you go 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\" 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['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>"; Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272593 Share on other sites More sharing options...
Gotharious Posted September 25, 2011 Author Share Posted September 25, 2011 anyone? please this is very urgent Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272658 Share on other sites More sharing options...
AyKay47 Posted September 25, 2011 Share Posted September 25, 2011 you have the roomid and hiddenid set to hidden input fields.. but you do not assign them values.. <input type='hidden' name='roomid' id='roomid' value='$something'/> Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272679 Share on other sites More sharing options...
Gotharious Posted September 25, 2011 Author Share Posted September 25, 2011 did that and still didn't work echo "<input name=\"roomid\" id=\"roomid\" type=\"hidden\" value=\"$roomid\">"; My point is I want the price per day for a room to be multiplied by the number of rooms, multiplied by the number of nights to give the total price in the form is was set as $nr is the price per day $pr is price per day multiplied by the number of rooms That's the form 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> Now for the other file bookingmanager.php where the confirmation page $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; Now I tried to add to the $totalprice = $roonsNo * $newdate * $pr (and then tried $nr) and still got nothing Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272692 Share on other sites More sharing options...
Pikachu2000 Posted September 25, 2011 Share Posted September 25, 2011 You need to start echoing the variables out individually to see what's going on with the values. All it takes is for one of them to be empty or zero to possibly crater the whole thing. Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272695 Share on other sites More sharing options...
Gotharious Posted September 25, 2011 Author Share Posted September 25, 2011 Total Price: 6 ($totalprice) Total Nights: 2 ($newdate) Total pr: ($pr) Total nr: ($nr) room id: ($roomid) Rooms id: Array ($roomsArray) Array ( [roomid] => [roomnum] => [hotelid] => 13 [datein] => 26 Sep 2011 [dateout] => 28 Sep 2011 [nrooms] => 3 [bookroom] => book ) Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272699 Share on other sites More sharing options...
AyKay47 Posted September 25, 2011 Share Posted September 25, 2011 yes that shows that the problem is in the roomid as we previously believed.. if you set the value to the hidden input field as i instructed and it is still turning out empty, then something is wrong with the $roomid variable. can you isolate where this is coming from Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272711 Share on other sites More sharing options...
Gotharious Posted September 25, 2011 Author Share Posted September 25, 2011 here is the form $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\">"; 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 for confirmation $roomid = $_POST['roomid']; $_SESSION['roomid'] = isset($_POST['roomid']) ? $_POST['roomid'] : $_SESSION['roomid']; $roomsarray = explode(",",$_POST['roomid']); $_SESSION['roomsarray'] = isset($_POST['roomid']) ? explode(",",$_POST['roomid']) : $_SESSION['roomsarray']; Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272719 Share on other sites More sharing options...
AyKay47 Posted September 25, 2011 Share Posted September 25, 2011 you are setting the value of $roomid to itself.. doesn't make sense.. you set the value of $roomid to the POST data where you use it as your value.. im not understanding.. there will need to be another place where you set your input value to an actual value Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272726 Share on other sites More sharing options...
Gotharious Posted September 26, 2011 Author Share Posted September 26, 2011 I don't really get what you mean, but I can post you the whole 2 files if you want me to, each file contains around 3 functions tho not that long code Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272733 Share on other sites More sharing options...
Gotharious Posted September 26, 2011 Author Share Posted September 26, 2011 Ok here is the whole code Hotelsmanager.php <?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\" 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['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']); } } ?> and BookingManager.php (the confirmation page) <?php include("hotelsManager.php"); ?> <?php include("config.php"); ?> <?php include("textManager.php"); ?> <?php function echoPostedData() { $dbo = new DB(); $hotelObj = new hotelManager(); $hotelID = $_POST['hotelid']; $roomID = $_POST['roomid']; $roonsNo = $_POST['roomsNo']; $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']; $_SESSION['pr'] = isset($_POST['pr']) ? $_POST['pr'] : $_SESSION['pr']; $_SESSION['nrooms'] = $_POST['nrooms']; $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>"; $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 "<tr><td class=text valign=top>Total Rooms: ".$roomID."</td></tr>"; echo "<tr><td class=text valign=top>Total Rooms: ".$nr."</td></tr>"; echo "<tr><td class=text valign=top>room id: ".$_SESSION['pr']."</td></tr>"; echo "<tr><td class=text valign=top> Rooms id: ".$roomsarray."</td></tr>"; echo "</table>"; echo '<pre>' . print_r($_POST,true) . '</pre>'; 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 />"; } } } echo "<hr>"; echo "</td>"; echo "</tr>"; echo "<tr>"; echo "<td align=\"right\">"; echo "<input type=\"submit\" name=\"submit\" id=\"submit\" value=\"Make the reservation\" />"; echo "</td>"; echo "</tr>"; echo "</table>"; echo "</form>"; } ?> P.S. I echoed alot of things in the confirmation page to see what does each one gives Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272756 Share on other sites More sharing options...
Gotharious Posted September 26, 2011 Author Share Posted September 26, 2011 Still nothing.... anyone please help Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1272836 Share on other sites More sharing options...
Gotharious Posted September 26, 2011 Author Share Posted September 26, 2011 Anyone? I'm going crazy over here Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1273011 Share on other sites More sharing options...
jcbones Posted September 26, 2011 Share Posted September 26, 2011 I suppose your room ID comes from your database? If that is right, then you are trying to set the hidden input value BEFORE any database interaction. Then after that, you assign the room id to a javascript array, populating some kind of roomnum select box. You are going to have to troubleshoot the whole roomid from generation to selection, which runs through that javascript. So, open up the script in your web browser, view source to see if the room id's are set. You may have to highlight the select box, and then view that source, since javascript will not always show up in the regular source. Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1273014 Share on other sites More sharing options...
jcbones Posted September 26, 2011 Share Posted September 26, 2011 NEVER MIND, just looked closer at the code: It looks as if you are trying to loop through php and insert javascript code that loops through the php values. You CANNOT mix PHP and Javascript like that. If you are pushing a PHP variable value to a javascript array, then you have to build the javascript array before setting it. Javascript has never met PHP, and PHP has never met Javascript. They reside in 2 different worlds, with only non-controlled flight between them. Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1273015 Share on other sites More sharing options...
Gotharious Posted September 26, 2011 Author Share Posted September 26, 2011 ok, don't know why I feel that stupid all of the sudden, but thanks so, I shouldn't be looping PHP with javascript. Ok, this might sound weird to you, but..... I didn't build that website, it was a developer who screwed things up and I have to fix it tonight or loose a lot, and I'm kinda of a newbie about this, so I don't really get what you mean, specially I know nothing about javascript so.... All I want to do is let the confirmation page get the input from the reservation page, and it gets all the input correct, the only thing It can't get is the price and room id I mean, why does all variables work except for this one? Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1273025 Share on other sites More sharing options...
Gotharious Posted September 26, 2011 Author Share Posted September 26, 2011 And another thing, please... as English isn't my first language, so using metaphors isn't a really good idea to make me understand tho. Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1273028 Share on other sites More sharing options...
jcbones Posted September 27, 2011 Share Posted September 27, 2011 Not trying to make you feel stupid, as this is a common mistake that we see a lot on here. Javascript is ran specifically on the clients machine (end user web browser). PHP is ran specifically on the server (end user never gets php code). You can tell PHP to write anything, but it cannot interact with it in any way other than writing it. If you wish javascript to build the form, you must pass the PHP variables as a javascript array. Now on to more important pertinent stuff. It is actually I who feels a slight bit stupid here. I saw the array.push(), and thought you were trying to insert javascript array's in a php while loop. But, after seeing the whole script (taking time to go through it), I see what it is doing. I also see the problem, which is another common one around here. 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\">"; This first bit of code explains it all. It is a scope problem. $roomID is not available because it hasn't been passed to the function. Only the hotelID, has been passed. So lets back up to my second to the last post. If room ID comes from the database, then you need to put: echo "<input name=\"roomid\" id=\"roomid\" type=\"hidden\" value=\"$roomID\"/>"; Inside the while loop. ***OR*** IF this variable comes from somewhere else, then you must pass it in the arguments. public function getHotelRooms($hotelID,$roomID) Also, your roomnums are not being passed, because you don't have a value assigned to it. echo "<input name=\"roomnum\" id=\"roomnum\" type=\"hidden\">"; //NO VALUE; Let me know if any of that was hard to understand, I don't have any second languages, all I speak is Southern! Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1273060 Share on other sites More sharing options...
Gotharious Posted September 27, 2011 Author Share Posted September 27, 2011 Thanks alot for your help, mate I did as you said, but unfortunately, it's still the same at the confirmation page Is there a way to pass the $pr variable from the form to the confirmation page? because that's all I need here is it's code in the form <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>"; Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1273183 Share on other sites More sharing options...
Gotharious Posted September 27, 2011 Author Share Posted September 27, 2011 OK, I might have asked in a wrong way ok.. now $pr variable is the multiplying of $nr * $row['price_per_day'] This is in a select dropdown list <?php for($i = 0; $i < $row['available_rooms']; $i++) { // as nr is the number of rooms you will select $nr = $i+1; // and pr is the number of rooms you've selected multiplied by the price per day for that room... // meaning if you choose 2 rooms, and each has a price per day rate of $100 the total will be $200 $pr=$nr * $row['price_per_day']; echo "<option value=$nr>$nr ($pr\$)</option>"; } Now what I want to do, is that the selection from this dropdown list that the client selects, to be passed to the confirmation page as Total price Which is supposed to be $totalprice = $newdate * $roonsNo * //// the price per day for that room which I can't get the variable to do so the multiplying of $newdate (number of nights) by $roonsNo (number of rooms) works great... but I want to add the price per day for that but I just can't Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1273267 Share on other sites More sharing options...
Gotharious Posted September 28, 2011 Author Share Posted September 28, 2011 anyone? Quote Link to comment https://forums.phpfreaks.com/topic/247833-having-a-problem-with-a-varialbe/#findComment-1273381 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.