Jump to content

Pass variable from one page to another


erme

Recommended Posts

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?

Link to comment
https://forums.phpfreaks.com/topic/190831-pass-variable-from-one-page-to-another/
Share on other sites

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\"> ...

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

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

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'] ;
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.