Jump to content

Having a problem with a varialbe


Gotharious

Recommended Posts

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'];

Link to comment
Share on other sites

  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

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.

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

)

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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'];

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

                   

Link to comment
Share on other sites

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.

 

                   

Link to comment
Share on other sites

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

 

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?

Link to comment
Share on other sites

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!

 

Link to comment
Share on other sites

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>";

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.