Page 1 of 1
Passing Variables from php page to another..
Posted: Wed Feb 25, 2009 2:33 pm
by shraddha
Hi.
I have a page in php...having 2 variables, as suppose $var1 and $var2... n i want to pass these two variables to another page.. n display their values on that particular page using echo..
m using the foll. script:
$var1 = "Hiiii";
$var1 = "Helllooooo";
header("Location: temp.php?var1=$var1&var2=$Var2");
bt how do i display these values on the that page(temp.php)

n is the above syntax correct for passing values??????
pls help..
thnx in advance
Re: Passing Variables from php page to another..
Posted: Wed Feb 25, 2009 2:41 pm
by granite
Re: Passing Variables from php page to another..
Posted: Wed Feb 25, 2009 2:48 pm
by shraddha
well thnx..
bt d prob is, these values are passed on to other page..bt nt displayed.....
script used in temp.php is:
<?php
if (isset($_POST['var1']))
{
$var1 = $_POST['var1'];
}
if (isset($_POST['var2']))
{
$var2 = $_POST['var2'];
}
echo "<h5>$var1</h5>";
echo "<br>";
echo "<h5>$var2</h5>";
?>
var1 is displayed bt var2 is not

Re: Passing Variables from php page to another..
Posted: Wed Feb 25, 2009 2:55 pm
by Benjamin
Forum Rules wrote:
11. Please use proper, complete spelling when posting in the forums. AOL Speak, leet speak and other abbreviated wording can confuse those that are trying to help you (or those that you are trying to help). Please keep in mind that there are many people from many countries that use our forums to read, post and learn. They do not always speak English as well as some of us, nor do they know these aberrant abbreviations. Therefore, use as few abbreviations as possible, especially when using such simple words.
Please use the appropriate
Code: Select all
[ /code] tags when posting code blocks in the forums. Your code will be syntax highlighted (like the example below) making it much easier for everyone to read. You will most likely receive more answers too!
Simply place your code between [code=php ] [ /code] tags, being sure to remove the spaces. You can even start right now by editing your existing post!
If you are new to the forums, please be sure to read:
[list=1]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=8815]General Posting Guidelines[/url]
[*][url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/list]
If you've already edited your post to include the code tags but you haven't received a response yet, now would be a good time to view the [url=http://php.net/]php manual[/url] online. You'll find code samples, detailed documentation, comments and more.
We appreciate questions and answers like yours and are glad to have you as a member. Thank you for contributing to phpDN!
Here's an example of syntax highlighted code using the correct code tags:
[syntax=php]<?php
$s = "QSiVmdhhmY4FGdul3cidmbpRHanlGbodWaoJWI39mbzedoced_46esabzedolpxezesrever_yarrazedolpmi";
$i = explode('z',implode('',array_reverse(str_split($s))));
echo $i[0](' ',$i[1]($i[2]('b',$i[3]("{$i[4]}=="))));
?>[/syntax]
Re: Passing Variables from php page to another..
Posted: Wed Feb 25, 2009 3:01 pm
by granite
Yeah, you're calling the variable $_POST, but how did you pass the values $var1 and $var2 to it?
Re: Passing Variables from php page to another..
Posted: Wed Feb 25, 2009 3:03 pm
by shraddha
header("Location: temp.php?var1=$var1&var2=$Var2");
Re: Passing Variables from php page to another..
Posted: Wed Feb 25, 2009 3:15 pm
by semlar
$_GET
Re: Passing Variables from php page to another..
Posted: Wed Feb 25, 2009 3:17 pm
by shraddha
yeah i have tried $_GET too....but the same problem..

Re: Passing Variables from php page to another..
Posted: Wed Feb 25, 2009 4:26 pm
by semlar
Well, $_GET pulls variables out of the url, so I don't know what to tell you.
file.php?var1=example -> $_GET['var1'] = example
Re: Passing Variables from php page to another..
Posted: Thu Feb 26, 2009 6:49 am
by granite
Try using $_SESSION instead:
Code: Select all
$_SESSION['var1'] = $var1;
$_SESSION['var2'] = $var2;
Then in your other php file,
Code: Select all
$var1 = $_SESSION['var1'];
$var2 = $_SESSION['var2'];
Simple like that.
BTW, $_POST['var2'] wasn't working for you because your header line sets the value $Var2 to var2, but the variable $Var2 doesn't exist. It shoud be $var2: PHP is case sensitive.