Jump to content

Am i passing the session wrong way? can someone please check.


Recommended Posts

 

i have page findroom.php that will redirect to the page DisplayDetails.php.

 

i wanted the DisplayDetails.php page to display data from the query in the page findroom.php. The data that i wanted to display from the query from page DisplayDetails is 'room_price' and 'room_type'.

 

However, when i clik the Book Now link, it dosesnt't display the value.

 

Since i'm just a starter in php, can someone tell me am i treating the session the right way as it doesn't diplay any result for the data that i wanted to take from the query in the findroom.php. But, for the the others data which is 'checkin', 'checkout' and others, it just show perfectly.

 

I do hope if someone can tell me am i using the session in the right way or not.

 

below is the code: findroom.php

 

<?php
session_start();
unset($_SESSION['error']);
// echo variable from the session, we set this on our other page
$_SESSION['checkin'] = $_POST['checkin'];
//$_SESSION['checkin']=$checkin;
$_SESSION['checkout'] = $_POST['checkout'];
$_SESSION['rooms']= $_POST['rooms'];
$_SESSION['adults']= $_POST['adults'];
$_SESSION['children']= $_POST['children'];
$days = (strtotime($_POST['checkout']) - strtotime($_POST['checkin'])) / (60 * 60 * 24);

$_SESSION['days']=$days;

$_SESSION['room_price']=$data['room_price'];
$room_price=$_SESSION['room_price'];

$_SESSION['room_type']=$data['room_type'];
$room_type=$_SESSION['room_type'];
?>

<html>
<body>
<form action="DisplayDetails.php" method="post">
<p>

<?php

//$result = mysql_query("SELECT id_no,room_type,room_price from room1 WHERE room_no NOT IN ( SELECT id_room_no
//FROM reservation1 WHERE datein >='$datein' AND dateout <='$dateout')");

$result = mysql_query("SELECT room_price, room_type from room1 WHERE room_no NOT IN ( SELECT id_room_no
FROM reservation1 WHERE datein >='$datein' AND dateout <='$dateout')");
?>

<?php 
    /*if(isset($_POST['Check']) && $_POST['Check']=='Submit') 
    { 
          echo "The rooms availale on the date of :";
	  echo $datein;
	  echo "  until  ";
          echo $dateout; 
    } */
?> 

</p>
<p><strong><strong>Room Availbility</strong> </p>
<td><table width="61%" height="64" border="1" cellpadding="0" cellspacing="0" bordercolor="#CC66CC" class="report2">
      <tr>
        <td width="190" bgcolor="#E8E8E8"><div align="center"><strong>Room Type </strong></div></td>
        <td width="218" bgcolor="#E8E8E8"><div align="center"><strong>Room Price </strong></div></td>
        <td bgcolor="#E8E8E8"><strong>Task</strong></div></td>
      </tr>
      <?php
	//$counter=1;
	while ($data = mysql_fetch_array($result)):
	?>
      <tr>
     
        <td><?php echo $data['room_type']; ?></td>
        <td><?php echo $data['room_price']; ?></td>
  <td width="153"><label><a href="DisplayDetails.php?id_no=<?php echo $data['id_no'];?>"><strong>Book Now</strong></a></label></td>


    </tr>
      <?php
  		//$counter++;
  		endwhile;
	?>
    </table>
  <table width="373" border="1">
     <tr>
       <td colspan="2"><strong>Reservation Summary</strong></td>
      </tr>
     <tr>
       <td>Check In :</td>
       <td><label>
         <?php echo $_SESSION['checkin']; ?>
       </label></td>
      </tr>
     <tr>
       <td>Check Out :</td>
       <td><label><?php echo $_SESSION['checkout']; ?></label></td>
      </tr>
     <tr>
       <td>Rooms :</td>
       <td><label><?php echo $_SESSION['rooms']; ?></label></td>
      </tr>
     <tr>
       <td>Adults Per Room :</td>
       <td><label><?php echo $_SESSION['adults']; ?></label></td>
      </tr>
     <tr>
       <td>Children Per Room :</td>
       <td><label><?php echo $_SESSION['children']; ?></label></td>
      </tr>
     <tr>
       <td>Days :</td>
       <td><?php echo $_SESSION['days']; ?></td>
     </tr>
   </table>
   <p>
    <label></label>
   </form>
  </body>
</html>

 

below is the code for : DisplayDetails.php

 


<?php
session_start();
$_SESSION['days']= $_POST['days'];
$_SESSION['room_price']= $_POST['room_price'];
$_SESSION['room_type']= $_POST['room_type'];

// echo variable from the session, we set this on our other page
//$_SESSION['checkin'] = $_POST['checkin'];
//$_SESSION['checkout'] = $_POST['checkout'];
//$_SESSION['rooms']= $_POST['rooms'];
//$_SESSION['adults']= $_POST['adults'];
//$_SESSION['children']= $_POST['children'];

?>

<html>
<body>
<h3><center>
   Room's Reservation
</center></h3>
<form action="DisplayDetails.php" method="post">

  <table width="373" border="1">
    <tr>
      <td colspan="2"><strong>Reservation Summary</strong></td>
    </tr>
    <tr>
      <td>Check In :</td>
      <td><label> <?php echo $_SESSION['checkin']; ?> </label></td>
    </tr>
    <tr>
      <td>Check Out :</td>
      <td><label><?php echo $_SESSION['checkout']; ?></label></td>
    </tr>
    <tr>
      <td>Rooms :</td>
      <td><label><?php echo $_SESSION['rooms']; ?></label></td>
    </tr>
    <tr>
      <td>Adults Per Room :</td>
      <td><label><?php echo $_SESSION['adults']; ?></label></td>
    </tr>
    <tr>
      <td>Children Per Room :</td>
      <td><label><?php echo $_SESSION['children']; ?></label></td>
    </tr>
    <tr>
      <td>Days :</td>
      <td><?php echo $_SESSION['days']; ?></td>
    </tr>
    <tr>
      <td>Room Type</td>
      <td><?php echo $_SESSION['room_type']; ?></td>
    </tr>
    <tr>
      <td>Room Price</td>
      <td><?php echo $_SESSION['room_price']; ?></td>
    </tr>
  </table>
</form>

</body>
</html>

 

any kinds of help really apprecited

you use $_POST for forms not passing on sessions.

 

remove this following code:

 

$_SESSION['days']= $_POST['days'];
$_SESSION['room_price']= $_POST['room_price'];
$_SESSION['room_type']= $_POST['room_type'];

from your displaydetails page and it should work

i try to trace the output based on the session using this cod :


echo "<pre>";
var_dump($_SESSION);
echo "</pre>"; 

 

it produce that this kind of result:


array( {
  ["checkin"]=>
  string(12) " 	2010-03-01"
  ["checkout"]=>
  string(12) " 	2010-03-24"
  ["rooms"]=>
  string(1) "1"
  ["adults"]=>
  string(1) "1"
  ["children"]=>
  string(1) "1"
  ["days"]=>
  int(23)
  ["room_price"]=>
  NULL
  ["room_type"]=>
  NULL
}


 

it shows that my room_type and room_price which is the data that i wanted to take from the query at the page findroom.php is NULL. i wonderi if i'm using the right code to take the data from query is right or not?

can someone tell me is this sysntax is right or not?

 


$_SESSION['room_price']=$data['room_price'];
$room_price=$_SESSION['room_price'];

$_SESSION['room_type']=$data['room_type'];
$room_type=$_SESSION['room_type'];

 

or can someone tell me is it actually possible to take the data from the query and the make it as session variable?

at the findroom.php page there's this query like below


$result = mysql_query("SELECT room_price, room_type from room1 WHERE room_no NOT IN ( SELECT id_room_no
FROM reservation1 WHERE datein >='$datein' AND dateout <='$dateout')");


while ($data = mysql_fetch_array($result)):

      <tr>
     
        <td><?php echo $data['room_type']; ?></td>
        <td><?php echo $data['room_price']; ?></td>

     </tr>

 

am i passing the wrong data to the session?

Look above this code:

 

$_SESSION['room_price']=$data['room_price'];
$room_price=$_SESSION['room_price'];

$_SESSION['room_type']=$data['room_type'];
$room_type=$_SESSION['room_type'];

 

Do you see any variables called $data?

 

Maybe thats why its not working.

the  variable $data actually come from here

 

   while ($data = mysql_fetch_array($result)):
   
      <tr>
        <td><?php echo $data['room_type']; ?></td>
        <td><?php echo $data['room_price']; ?></td>
</tr>

 

fuh..i do really need help here.. i wonder if i'm assigning it falsely to the array

$_SESSION['room_price']=$data['room_price'];
$room_price=$_SESSION['room_price'];

$_SESSION['room_type']=$data['room_type'];
$room_type=$_SESSION['room_type'];

 

Yes but the thing is...

 

Ermm how to explain this

 

Where it says data on the bottom, It needs to be above well the data because for instance you have a variable like this:

 

echo $variable;

$variable = test;

 

It will not work because the variable $variable is AFTER the echoing.

The same applies to the start of ur code...

thanks Ruzzas for all the efforts to help me. yeah, the probs come from the wrongly flow of the code. I finaly realize that...

 

you did really help knocked me some sense about the variables...i'm the one who doesn't make sense here with the code.

thanks again!! :D

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.