Hello All,

Is there a way how we can pass a PHP variable whose value has been retrieved from MySQL database to the next page?

Initially I tried this which didnt help me anyway.

// if user login information is CORRECT then redirecting them to the user home page

//retrieving realted userid from db for passing it to next pages

$query="select id from usertable where user='".$_POST['usrname']."' limit 1";
$result = mysql_query($query) or die();
$row = mysql_fetch_object($result);
$passit = $row->id; 

//echo $passit;  =>> this is displaying exactly what i wanted but how to pass this php variable value to the next page? I tried using form ACTION method but I guess it can't pass a PHP variable data to next page!

header("Location: userhomepage.php");

I heard sessions can serve this problem but as I am not familiar with sessions I would like to find if there is some easier way for doing this.Can anyone help me with this!

Thankyou in Advance.


10 Years
Discussion Span
Last Post by Kavitha Butchi

header("Location: userhomepage.php");

One was to pass this variable without sessions is to use the $_GET vars... like this:

header("Location: userhomepage.php?passit=$passit");

Then on the userhomepage.php have some code like this at the top:

if (isset($_GET['passit'])) {
     $passit = $_GET['passit'];
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.