erme Posted February 3, 2010 Share Posted February 3, 2010 Hi, I'm trying to pass a variable ($mailtobus) from Page1 to Page2. The variable is an email address that is pulled from a database. This is currently how I've coded it: <form action=\"/contact.php?mailtobus=" . $r['Email'] . "\" method=\"POST\"> This works perfect for what I want, but the email address obviously gets displayed in the address bar .. not ideal! Question is, is there a better way to do this so that the user cannot see the email address? Quote Link to comment https://forums.phpfreaks.com/topic/190831-pass-variable-from-one-page-to-another/ Share on other sites More sharing options...
premiso Posted February 3, 2010 Share Posted February 3, 2010 There is a way better way, use sessions to pass it. This will keep it internal to the server. Quote Link to comment https://forums.phpfreaks.com/topic/190831-pass-variable-from-one-page-to-another/#findComment-1006361 Share on other sites More sharing options...
erme Posted February 3, 2010 Author Share Posted February 3, 2010 Something like this? $countsql = "SELECT * FROM Table"; $inter = mysql_query("$countsql"); while($r = mysql_fetch_array($inter)) { $emailaddress = . $r['EmailBus'] . "\" $_SESSION['emailses'] = $emailaddress; echo "<form action=\"/contact.php?"\" method=\"POST\"> ... Quote Link to comment https://forums.phpfreaks.com/topic/190831-pass-variable-from-one-page-to-another/#findComment-1006372 Share on other sites More sharing options...
dmikester1 Posted February 3, 2010 Share Posted February 3, 2010 Sure. Ditch the '?' and you don't need a slash in front of the URL. Make sure your first line of code on both pages is: <?php session_start(); ?> or sessions won't work. The other way to would be to pass the email address via POST. http://www.tizag.com/phpT/examples/formex.php Mike Quote Link to comment https://forums.phpfreaks.com/topic/190831-pass-variable-from-one-page-to-another/#findComment-1006383 Share on other sites More sharing options...
erme Posted February 3, 2010 Author Share Posted February 3, 2010 OK I think ive set up the session on Page1. How can I carry the variable across to Page2 (on submit of form) Do I need something like <?php session_start(emailses); ?> Quote Link to comment https://forums.phpfreaks.com/topic/190831-pass-variable-from-one-page-to-another/#findComment-1006404 Share on other sites More sharing options...
erme Posted February 3, 2010 Author Share Posted February 3, 2010 I have this in page1 $inter = mysql_query("$countsql"); while($r = mysql_fetch_array($inter)) { $mailtobus = $r['EmailBus'] ; $_SESSION['emailses'] = $mailtobus; } echo "Ses = ". $_SESSION['emailses']; //retrieve data The echo outputs correctly. I have this in page2 echo "Ses = ". $_SESSION['emailses']; //retrieve data However the session is not carried across Quote Link to comment https://forums.phpfreaks.com/topic/190831-pass-variable-from-one-page-to-another/#findComment-1006418 Share on other sites More sharing options...
$Three3 Posted February 3, 2010 Share Posted February 3, 2010 I have this in page1 $inter = mysql_query("$countsql"); while($r = mysql_fetch_array($inter)) { $mailtobus = $r['EmailBus'] ; $_SESSION['emailses'] = $mailtobus; } echo "Ses = ". $_SESSION['emailses']; //retrieve data The echo outputs correctly. I have this in page2 echo "Ses = ". $_SESSION['emailses']; //retrieve data However the session is not carried across Okay, the code above should start with <?php session_start(); ?> before you assign any values to the $_SESSION array. Once you have stored the value such as the email address to the $_SESSION array, you can then access this value on any other page like so: <?php session_start() ; echo $_SESSION['emailses'] ; ?> Quote Link to comment https://forums.phpfreaks.com/topic/190831-pass-variable-from-one-page-to-another/#findComment-1006426 Share on other sites More sharing options...
erme Posted February 3, 2010 Author Share Posted February 3, 2010 Found the problem, <?php session_start(); ?> wasn't above the <html> tag Silly me! Quote Link to comment https://forums.phpfreaks.com/topic/190831-pass-variable-from-one-page-to-another/#findComment-1006436 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.