Page 1 of 1

Passing Variable Using Session

Posted: Wed Apr 28, 2010 8:50 am
by nitediver
On the "first.php" page, the variable value(inside the session) deliver successfully, but on the "next.php" the session display nothing.
Its weird, since I also use session for login system and work without problem.

This is code from page before "first.php".

Code: Select all

<form name=\"update\" method=\"post\" action=\"z_reg_sess.php?prod_id=$prod_id\">

Code: Select all

<?
//first.php
include "function.php";
connect();

$_SESSION['prod_id'] = $_GET['prod_id'];

$_SESSION['size_id'] = htmlentities($_POST['size_id'], ENT_QUOTES);

echo "Product : ".$_SESSION['prod_id'];
echo "<br>";
echo "Size : ".$_SESSION['size_id'];
echo "<br>";
echo "<a href=\"z_next.php\">Next</a>";
?>
first.php Result:
--------------
Product : 12
Size : 1
--------------

Code: Select all

<?
//next.php
include "function.php";
connect();
session_start();

$_SESSION['prod_id'] = $prod_id = $_GET['prod_id'];
$_SESSION['size_id'] = $size_id = $_GET['size_id'];

echo "Product : ".$_SESSION['prod_id'];
echo "<br>";
echo "Size : ".$_SESSION['size_id'];
?>
next.php Result
-----------
Product :
Size :
-----------

Re: Passing Variable Using Session

Posted: Wed Apr 28, 2010 10:06 am
by TheBrandon
Are you passing the GET variable on next.php?

You're saying:

Code: Select all

$_SESSION['prod_id'] (which is 12) = $prod_id (which has no value yet) = $_GET['prod_id']
So if you don't have a get value set, you're setting the session to be nothing.

Try removing:

Code: Select all

$_SESSION['prod_id'] = $prod_id = $_GET['prod_id'];
$_SESSION['size_id'] = $size_id = $_GET['size_id'];
On next.php

Re: Passing Variable Using Session

Posted: Wed Apr 28, 2010 3:52 pm
by Jonah Bron
And it doesn't look like you're calling session_start() on first.php.

Re: Passing Variable Using Session

Posted: Thu Apr 29, 2010 2:16 am
by nitediver
@TheBrandon
Thanks, Ill try your advice.

@Jonah Bron
Yeah I forgot.