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.

David

Member Avatar for deleted1234

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.

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:

displayitems.php?category=1
displayitems.php?category=2

etc.

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.

Member Avatar for diafol

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.

Member Avatar for rajarajan2017

<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.

Member Avatar for diafol

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

May I suggest that you DO NOT use $_REQUEST - this could be very dangerous. The problems involved with it have been well documented (for years). Here's a brief description:

http://stackoverflow.com/questions/2142497/whats-wrong-with-using-request

Member Avatar for rajarajan2017

Yes I agree with ardav, it is also an option there, for practice it should be avoided

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.