Grundizer Grundizer - 7 months ago 42
PHP Question

Passing multiple variables to another page in url

I'm passing a variable to another page in a url using sessions like this but it seems that I can't concatenate another variable to the same url and retrieve it in the next page successfully

Page 1

session_start();
$event_id = $_SESSION['event_id'];
echo $event_id;

$url = "http://localhost/main.php?email=" . $email_address . $event_id;


Page 2

if (isset($_GET['event_id'])) {
$event_id = $_GET['event_id'];}
echo $event_id;


echo $event_id
shows an error
Undefined variable
on page 2 but if I use just the
event_id
in the
$url
like here

$url = "http://localhost/main.php?event_id=" . $event_id;


That works fine, but I need to be able to use both variables in the url so that page 2 can retrieve get them.

Answer

Use the ampersand & to glue variables together:

$url = "http://localhost/main.php?email=$email_address&event_id=$event_id";
//                               ^ start of vars      ^next var