problems with passing session variable to another page.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Locked
aarhus
Forum Newbie
Posts: 2
Joined: Thu Mar 22, 2007 3:12 am

problems with passing session variable to another page.

Post by aarhus »

Hello there,

I have got one problem here. This is the main php file:

<?

session_start();

include "../inc/dbconnect.php";

?>

<html>
<head>
<title>Search</title>
<meta http-equiv="Content-Type" content="text/html; windors-1271">
</head>

<body bgcolor="#FFFFFF" text="#000000">



<?

switch( $_GET["action"] )
{
case "search": // show search results
{
include_once("../inc/search_results.php");
break;
}

case "details": // show search results
{
include_once("../inc/products.php");
break;

}

default: // default search form
{
include_once("../inc/search.php");
break;
}

}

?>

</body>
</html>

So, when I get a list of search results on search_results.php I want to click on any search_result and I want to pass the row['filmid'] to the page products.php so that products.php will display all info about any product. The problem is that when I get the row id with $_session['filmid'] from search_results.php to products.php, I get the id of the only the last search_result but not the one I click. I dont get the reason for that.

This is my search_results.php page:

<?

.......................

//echo ("$query");

include_once("dbconnect.php");
$result = mysql_query($query);

$num_results = @mysql_num_rows($result);

echo '<p>Number of DVDs found: '.$num_results.'</p>';

for ($i=0; $i <$num_results; $i++)
{
$row = mysql_fetch_assoc($result);
echo '<p><strong>' .($i+1). 'Title: <a href="search_form.php?action=details"></a></strong><br />';
echo 'Items in Stock: ' . $row['itemsinstock'] . '<br /> ';
echo 'Extrainfo: ' . $row['extrainfo'] . '<br />';
echo 'Price: ' . $row['price'] . '</p>';



$_SESSION['filmid']=$row['filmid'];

echo ($_SESSION['filmid']);


}


?>

I hope you can help me with this problem.

Thanks in advance
User avatar
dhrosti
Forum Commoner
Posts: 90
Joined: Wed Jan 10, 2007 5:01 am
Location: Leeds, UK

Post by dhrosti »

You need session_start() at the top of 'search_results' aswell.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Duplicate thread + no syntax tags = :evil:
Locked