Passing Multiple Variables to Another Page in URL
In the pursuit of sharing multiple variables across pages via URL parameters, the use of sessions alone may seem restrictive. However, by incorporating the ampersand (&) character, this limitation can be overcome.
Solution:
Let's revisit the code in the question:
Page 1:
<code class="php">session_start(); $event_id = $_SESSION['event_id']; echo $event_id; $url = "http://localhost/main.php?email=" . $email_address . "&event_id=" . $event_id; // ^ add ampersand here</code>
Page 2:
<code class="php">if (isset($_GET['event_id'])) { $event_id = $_GET['event_id']; } echo $event_id;</code>
By adding the ampersand between the concatenated variables, we effectively glue them together in the URL. This ensures that both variables can be retrieved on Page 2:
<code class="php">$event_id = $_GET['event_id']; // successfully retrieved</code>
In this manner, you can effectively pass multiple variables in a URL, enabling seamless data exchange between pages.
The above is the detailed content of How can I pass multiple variables to another page in a URL using the ampersand (&)?. For more information, please follow other related articles on the PHP Chinese website!