Hello Everyone,

I know that you pas variables with the $_GET method, but i am unsure as to how or why. When is this action called for? Thanks for helping me clear up my confusion.


8 Years
Discussion Span
Last Post by rajarajan2017

Use $_GET whenever your form method is declared as GET like this:

<form action="test.php" method="get">
Name: <input type="text" name="txtname" />

On your test.php page, you get the values of the form by doing:
$name = $_GET

Quoting this:

When to use method="get"?
When using method="get" in HTML forms, all variable names and values are displayed in the URL.
Note: This method should not be used when sending passwords or other sensitive information!

However, because the variables are displayed in the URL, it is possible to bookmark the page. This can be useful in some cases.
Note: The get method is not suitable for large variable values; the value cannot exceed 100 characters.

Edited by deleted1234: n/a


More often than not you use the query string (the data in the URL that is fetched with $_GET) to pass data between pages which is used when selecting the content to be displayed.

For example if you had a file that could display products from three different categories you may select the category to display via the URL like this:



You could use the value in an SQL query like this:

mysql_query("SELECT * FROM items WHERE catid = ".mysql_real_escape_string($_GET['category']));

Hope that helps clear things up a bit.


Listen to etftw. Forget that send forms via GET method. Forms should be sent by POST.

As mentioned, all GET (and POST) data MUST be cleaned before using them in queries.


<form action="test.php" method="post">
When using post you can get the value on other pages with $_POST;
<form action="test.php" method="get">
when using get you can get the value on other pages with $_GET;
for this method you can see the variable result on query string.

If you want to retreive the value whatever it is (USING post or get), you can get the value on other pages with $_REQUEST

All are send/recieve values from one page to another page.

Edited by rajarajan2017: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.