TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-20-2010, 08:44 AM   #1 (permalink)
The Wanderer
 
Join Date: Mar 2010
Posts: 14
Thanks: 4
fairytale89 is on a distinguished road
Default Am i passing the session wrong way? can someone check.

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: lookroom.php(this is the starter page)
Code:
<?php
session_start();
//unset($_SESSION['error']);

$_SESSION['checkin']=$checkin;
$_SESSION['checkout']=$checkout;
$_SESSION['rooms']=$rooms;
$_SESSION['adults']=$adults;
$_SESSION['children']=$children;

?> 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" media="all" href="calendar-win2k-1.css" title="win2k-cold-1" />
<script type="text/javascript" src="Kalendar/calendar.js"></script>
<script type="text/javascript" src="Kalendar/calendar-en.js"></script>
<script type="text/javascript" src="Kalendar/calendar-setup.js"></script>
<script type="text/javascript" src="Kalendar/ew.js"></script>
<script type="text/javascript"></script>
<title>SistemAPOS</title>
<style type="text/css">
<!--
.style7 {color: #FFFFFF}
.style8 {
	color: #000000;
	font-weight: bold;
}
.style10 {color: #FFFFFF; font-weight: bold; }
.style11 {font-weight: bold}
-->
</style>

</head>

<body>

<form action="findroom.php" method="post">

  <p>Check Room Availbility</p>
  <p>Check In
    <label>
      <input type="text" name="checkin" value="<?php $checkin ?>"/>
      <input name="datein" type="image" id="dateA" src="Kalendar/ew_calendar.gif" width="16" height="15" border="0" />
  <script type="text/javascript">
					</script>
            </strong>
  <script type="text/javascript">Calendar.setup(
					{
						inputField : "datein", // ID of the input field
						ifFormat : "%Y-%m-%d", // the date format
						button : "dateA" // ID of the button
					}
					);
					document.write(ifFormat);
					</script>
      </label>
  </p>
  <p>Check Out 
    <input name="checkout" type="text" id="checkout" value="<?php $checkout ?>"/>
    <input name="dateout" type="image" id="dateB" src="Kalendar/ew_calendar.gif" width="16" height="15" border="0" />
    </strong>
    <script type="text/javascript">Calendar.setup(
					{
						inputField : "dateout", // ID of the input field
						ifFormat : "%Y-%m-%d", // the date format
						button : "dateB" // ID of the button
					}
					);
					document.write(ifFormat);
					</script>
  </p>
  <p>Rooms : 
    <label>
    <select name="rooms" id="rooms" value="<?php $rooms;?>">
      <option>1</option>
      <option>2</option>
      <option>3</option>
      <option>4</option>
      <option>5</option>
    </select>
    </label>
  Adults Per Room : 
  <label>
  <select name="adults" id="adults" value="<?php $adults;?>">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
  </select>
  </label>
  Children Per Room : 
  <label>
  <select name="children" id="children" value="<?php $children;?>">
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
    <option value="5">5</option>
  </select>
  </label>
  </p>
  <p>
    <label>
      <input type="submit" name="Check" id="Check" value="Submit" />
    </label>
  </p>
</form>
</body>
</html>

below is the code: findroom.php

Code:
<?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

Code:
<?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
fairytale89 is offline  
Reply With Quote
Old 03-20-2010, 05:35 PM   #2 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

php Code:
$_SESSION['room_price']=$data['room_price'];
$room_price=$_SESSION['room_price'];

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

$data doesn't exist at this stage where you are setting it. Therefore the above lines are extraneous as you're setting $_SESSION's room_price and room_type key from a NULL variable and then passing it along to others ($room_price and $room_type) which then aren't used. var_dump() any of these variables to check them for yourself.

php Code:
<?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;
        ?>

Since you are generating a list of data inside of a while loop, passing this information along via session variables would be difficult to nearly impossible. You'd be much better off passing it along via GET.

php Code:
<?php
    while ( $data = mysql_fetch_assoc( $result ) ):
        $q = http_build_query( array( 'id_no' => $data['id_no'], 'room_type' => $data['room_type'], 'room_price' => $data['room_price'] ), '', '&amp;' );
?>
    <tr>
        <td><?php echo $data['room_type']; ?></td>
        <td><?php echo $data['room_price']; ?></td>
        <td width="153"><label><a href="DisplayDetails.php?<?php echo $q ; ?>"><strong>Book Now</strong></a></label></td>
    </tr>
<?php endwhile; ?>

Then in DisplayDetails.php you could grab those values and enter them into the session for use later;

php Code:
if ( isset( $_GET ) ) {

    foreach ( $_GET as $k => $v ) {

        if ( in_array( $k, array( 'id_no', 'room_type', 'room_price' ) ) )
            $_SESSION[$k] = $v

    }

}

Please note that the above example is unsafe and does not include error checking of the values it is receiving. You will have to address this yourself, all the code above does is find the keys it wants to assign to the session and assigns them.
delayedinsanity is offline  
Reply With Quote
Old 03-20-2010, 11:18 PM   #3 (permalink)
The Wanderer
 
Join Date: Mar 2010
Posts: 14
Thanks: 4
fairytale89 is on a distinguished road
Default

thanks delayedinsanity for the reply.I really appreciate the efforts to help me and assist me with some solutions.

I did actuall go through my code again and managed to fix the code.The prob is because the flow of my code is not right.And i finally managed to get the output that i wanted.

Thanks again..cheers
fairytale89 is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Destroy Session when close browser Mike General 3 07-09-2009 10:53 PM
Huge Session Problem Killswitch General 1 11-17-2008 01:36 AM
Session security Blackbrain Absolute Beginners 3 01-07-2008 10:19 PM
Understanding the Life of a Session Wildhoney General 6 10-27-2007 02:34 AM
Lowdown on Passing Things as Reference Wildhoney General 0 09-28-2007 10:57 AM


All times are GMT. The time now is 11:16 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design