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.

KavithaButchi.

Recommended Answers

All 2 Replies

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:

//userhomepage.php
if (isset($_GET['passit'])) {
     $passit = $_GET['passit'];
}

Thanks a Ton Daedal. This worked!!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.