Page 1 of 1

problems with passing session variable to another page.

Posted: Thu Mar 22, 2007 3:16 am
by aarhus
Hello there,

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

Code: Select all

<?

	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:

Code: Select all

<?

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

//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

d11wtq | Please wrap

Code: Select all

 [/ php] tags around your code when posting <?php ?> code in the forum[/color][/b]

Posted: Thu Mar 22, 2007 3:44 am
by volka
Why is this in DevNetwork Forums Forum Index -> PHPDN Suggestions ?

Posted: Thu Mar 22, 2007 4:09 am
by Chris Corbyn
:arrow: Moved to PHP Code