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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.