Passing Variable to the Next Page in PHP
Passing Variable in PHP
I wanted to pass a variable to the next page using PHP/MySQL and then retrieve/use it there. After a bit of searching and reading on the internet, I found a really easy way to do it and now I'll be sharing this information with you in this article.
Here is an example:
I have two pages
1) A login page (for the user to submit his/her username and password.)
2) A welcome page (which will be loaded in case the username and password is correct.)
The variable to be passed is '$login'. It will be assigned to another variable i.e. $id and used in the welcome page.
In this method the variable will be passed through the URL. Just add ?id=$login to the URL and you are almost done.
In my case the example would be:
Then retrieve this variable on the welcome page using "$_GET". Here is the example:
$name = $_GET['id'];
(This code will not only get the id and save it in a new variable name but also print it.)
Now you are done and you are free to use this variable anywhere in this page in the form of &name.
More by this Author
Here are some nice quotes about women. A collection of quotes about women for all of you to read. A woman's strength is the irresistible might of weakness. Ralph Waldo Emerson A woman can say more in a sigh than a...
Growing new plants saves you money and it is fun. It is an amazing experience watching your seeds turning into seedlings and then turning into trees. Here are two main methods of propagating palm trees. You can grow...
I have collected these random facts from various sources on the internet(like Wikipedia), so they may or may not be true. Now please proceed to reading these interesting random bits. Butterflies cannot fly if their...