Create dynamic sites with PHP & MySQL - Passing variables
(Page 11 of 16 )
Let's take a different view now and consider how information can be passed to another PHP page. One method is by using forms as we have done already; another is by using query strings. What are query strings? Change the line method="post" to method="get" in our script input. php. Now try submitting new data into the database with it. After clicking submit you will see our familiar "Thank you! Information entered" in the browser. But look at the URL. It looks something like:
Look closely. Now the information is passed as a string in the URL instead of posting directly. The sentence after the ? is the query string, and as you can see it contains the name of the variable and its values. When PHP receives a query string like ?first=John it automatically creates a variable named $first and assigns the value from the query string to it. So it is equivalent to $first="John"; When more than one variable is present, the variables are separated by an ampersand (&).
If you don't have the register_globals=on option enabled, be sure to initialize the variables with $_GET like $first=$_GET[first];