...

View Full Version : session problem



Gez
05-14-2008, 10:30 PM
Ok so heres the problem i have one variable on the first page which is $DestinationName and i want to use it on my second page but i can't seem to get the sessions to work and get it to carry it to take it to the second page, what can i do

firstpage:

<link rel="stylesheet" type="text/css" href="style.css" />

<?php

session_start();

Include ("dbconnect.php");

Function form(){
echo "
<form action='".$_SERVER['PHP_SELF']."' method='GET'>
<table align='center' width='200' border='0'>
<tr>
<td align='center'>Destination:</td>
<td align='center'>Flying from:</td>
</tr>
<tr>
<td><input type='text' name='destination'></td>
<td><input name='flyfrom' type='text'></td>
</tr>
<tr>
<td align='center'>Date (YYYY-MM-DD)</td>
<td align='center'>Date (YYYY-MM-DD)</td>
</tr>
<tr>
<td><input name='depdate' type='text'></td>
<td><input name='retdate' type='text'></td>
</tr>
<tr>
<td colspan='2' align='center'><input type='submit' value='Take me there!'></td>
</tr>
</table>
</form><hr>";
}

Function ShowDepFlights (){
$table_flight="flight";
// Set Sessions
$DestinationName=$_REQUEST['destination'];
$DepDate=$_REQUEST['depdate'];
$FlyingFrom=$_REQUEST['flyfrom'];
$RetDate=$_REQUEST['retdate'];
// Define the query
$querydep="SELECT * FROM $table_flight
WHERE DestinationAirport ='".$DestinationName."'
AND DepartureDate ='".$DepDate."'
AND DepartureAirport ='".$FlyingFrom."'";
// Do the query
$resultdep = mysql_query($querydep) or die(mysql_error());

echo "Select your flights: <br/><br/> <b> OUTBOUND flights </b> <br/><br/>
<table width='800' border='1'>
<tr>
<td align='center'><b>Destination:</b> </td>
<td align='center'><b>Airline:</b></td>
<td align='center'><b>Departure Airport:</b></td>
<td align='center'><b>Departure Date:</b></td>
<td align='center'><b>Departure Time:</b></td>
<td align='center'><b>Cost:</b></td>
<td align='center'></td>
</tr>
<form action='hotelfinder.php' method='GET'>";

// Display the results
while ($row = mysql_fetch_array( $resultdep )){
echo "<tr>";
echo " <td align='center'>".$row['DestinationAirport']."</td>";
echo " <td align='center'>".$row['Airline']."</td>";
echo " <td align='center'>".$row['DepartureAirport']."</td>";
echo " <td align='center'>".$row['DepartureDate']."</td>";
echo " <td align='center'>".$row['DepartureTime']."</td>";
echo " <td align='center'>".$row['Fare']."&euro;</td>";
echo " <td align='center'><input type='radio' name='depflight' value='".$row['Id']."'></td>";
echo " </tr>";
}
echo "</table><br/><hr><br>";
}

Function ShowRetFlights (){
$table_flight="flight";
// Set Sessions
$DestinationName=$_REQUEST['destination'];
$FlyingFrom=$_REQUEST['flyfrom'];
$RetDate=$_REQUEST['retdate'];
// Define the query
$queryret="SELECT * FROM $table_flight
WHERE DestinationAirport ='".$FlyingFrom."'
AND DepartureDate ='".$RetDate."'
AND DepartureAirport ='".$DestinationName."'";
// Do the query
$resultret = mysql_query($queryret) or die (mysql_error());

echo "<b> INBOUND flights </b> <br/><br/>
<table align='center' width='800' border='1'>
<tr>
<td align='center'><b>Destination: </b></td>
<td align='center'><b>Airline:</b></td>
<td align='center'><b>Departure Airport:</b></td>
<td align='center'><b>Departure Date:</b></td>
<td align='center'><b>Departure Time:</b></td>
<td align='center'><b>Cost:</b></td>
<td align='center'></td>
</tr>";

// Display the results
while ($row = mysql_fetch_array( $resultret )){
echo "<tr>";
echo " <td align='center'>".$row['DestinationAirport']."</td>";
echo " <td align='center'>".$row['Airline']."</td>";
echo " <td align='center'>".$row['DepartureAirport']."</td>";
echo " <td align='center'>".$row['DepartureDate']."</td>";
echo " <td align='center'>".$row['DepartureTime']."</td>";
echo " <td align='center'>".$row['Fare']."&euro;</td>";
echo " <td align='center'><input type='radio' name='retflight' value='".$row['Id']."'></td>";
echo " </tr>";
}
echo "</table><br/><input type='submit' value='Resorts'>
</form><br/><hr><br>";
}


echo "
<html>
<head>
<title> Lufbra Travel </title>
</head>
<body>
<h1>Lufbra Travel</h1> ";

form();

ShowDepFlights();

ShowRetFlights();

// Set sessions that are going to be used later
$_SESSION['destination']=$DestinationName;

echo "
&copy; Geraint Fisher 2008
</body>
</html> ";

?>

secondpage:

<link rel="stylesheet" type="text/css" href="style.css" />

<?php

session_start();
// Set sessions for the flights ID's
$depflight=$_REQUEST['depflight'];
$_SESSION['depflight']=$depflight;
$retflight=$_REQUEST['retflight'];
$_SESSION['retflight']=$retflight;

$DestinationName=$_SESSION['destination'];

Include ("dbconnect.php");

Function showhotels(){

$table_hotel="hotel";

$DestinationName=$_SESSION['destination'];
// Set query
$queryhotel="SELECT * FROM $table_hotel
WHERE Resort = '".$DestinationName."'";
// Do query
$hotelresult = mysql_query($queryhotel) or die (mysql_error());

echo "<table width='300' border='1'>
<tr>
<td align='center'><b>Resort:</b> </td>
<td align='center'><b>Website:</b></td>
<td align='center'><b>Star Rating</b></td>
<td align='center'><b>Score</b></td>
<td align='center'><b>Cost of Single room:</b></td>
<td align='center'><b>Cost of Double room:</b></td>
<td align='center'></td>
</tr>";

// Show results
while ($row = mysql_fetch_array( $hotelresult )){
echo "<tr>";
echo " <td align='center'>".$row['Resort']."</td>";
echo " <td align='center'>".$row['WebAddress']."</td>";
echo " <td align='center'>".$row['Star']."</td>";
echo " <td align='center'>".$row['Score']."</td>";
echo " <td align='center'>".$row['SingleRoom']."</td>";
echo " <td align='center'>".$row['DoubleRoom']."</td>";
echo " <td align='center'></td>";
echo " </tr>";
}
echo "</table><br/><hr><br>/";
}

echo "
<html>
<head>
<title> Lufbra Travel </title>
</head>
<body>
<h1>Lufbra Travel</h1>
Destination:<b>".$DestinationName."</b> <br/>Want somewhere else? Click <a href='flightfinder.php'>here</a>
<br/><br/>Availible resorts:";



echo "
<hr><br/>
&copy; Geraint Fisher 2008
</body>
</html> ";

?>

logictrap
05-15-2008, 12:04 AM
Have you checked to make sure the $_SESSION variable on page one contains a value?

Fou-Lu
05-15-2008, 12:45 AM
At the bottom of your first page, try echoing out your $_SESSION['destination'] after you set it to the destination name. If you do not get output, it is because you do not have output buffering enabled in your ini (which is fine personally I prefer no output buffering).
If this is the case, fix it by changing the top of your file, something simple like this:


<link rel="stylesheet" type="text/css" href="style.css" />

<?php

session_start();

to


<?php
session_start();
?>
<link rel="stylesheet" type="text/css" href="style.css" />
<?php
// more stuffs

Session start needs to send a header to the browser to try and track via cookies - the link rel at the top pushes output to the browser before headers can be sent (you can see if this is the case by running against error_reporting(E_ALL))
If this is not the solution, it is possible that you have cookies disabled on your browser. By default, php sessions require the use of cookies if I'm not mistaken, so you may want to run some ini setters:


ini_set('session.use_cookies', 1); // Allow cookies to store the session id
ini_set('session.use_only_cookies', 0); // normally this is 1, but shut it down to allow non-cookie browsers to use sessions
ini_set('session.use_trans_sid', 1); // I think thats the right name I always mess this one up

Transparent session ids automatically append a session identifier at the end of links (not headers so be careful if you redirect), which makes it awefully sweet!

Hope that helps!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum