Page 1 of 1

problems with passing session variable to another page.

Posted: Thu Mar 22, 2007 3:57 am
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

Posted: Thu Mar 22, 2007 4:04 am
by dhrosti
You need session_start() at the top of 'search_results' aswell.

Posted: Thu Mar 22, 2007 7:52 am
by feyd
Duplicate thread + no syntax tags = :evil: