Jump to content

Having a problem with a varialbe


Gotharious

Recommended Posts

  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

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.

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

)

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

)

 

Link to comment
Share on other sites

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

        )

Link to comment
Share on other sites

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
)

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.