Dynadot

[Tutorial] on $_POST & $_GET

Spaceship Spaceship
Watch

NetworkTown.Net

Account Closed
Impact
2
Hi

Im going to explain $_POST & $_GET that iv learnt about on php.net,

$_POST is used to get infomation from a form like say your form was like this:

HTML:
<form action='something.php' method='post' enctype="multipart/form-data">

<input name="name" type="text" size="45" />

</form>

Now when that form gets submitted you want to get the persons name to show it up on the thank you page or something you use $_POST to get the name. You do that by doing this:

PHP:
<?php

$user = $_POST['name'];

 //the place where it says name is that name of the form //above thats where the user puts there name and the form box is called name

echo 'Thank you $user for submitting your infomation to our site bla bla';

?>

So thats how you use $_POST now i will show you how to use $_GET

you use $_GET to get infomation that is in the address bar, this is how to use it.

PHP:
<?php 

$name = $_GET['name'];

echo 'Thank you $name for soemthing bla bla';

?>

Now $_GET will go to the address bar and find name= for example if your address bar address was: http://www.site.com/index.php?name=john

The script will get john as the name and put that in the sentence. Hope this helps took me a bit of time to figer it out on php.net but i got there and i though i would share it here.
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GET can still be used to retrieve information from a form, it's just that that information is passed from the form to the server via the address / URL.

Traditionally, GET was used as a way of getting information whereas POST was used to send information. That is to say, traditionally a GET request should not make changes on the server (whereas POSTs can).

This is actually a good way to think, anyway. People that have browser accelerators that prefetch URLs will have lots of problems if GET type URLs are prefetched and if those URLs actually make a change on the server. Imagine prefetching 100s of URLs that are actually 'Delete this Entry' type URLs!
 
0
•••
TwistMyArm said:
GET can still be used to retrieve information from a form, it's just that that information is passed from the form to the server via the address / URL.

Traditionally, GET was used as a way of getting information whereas POST was used to send information. That is to say, traditionally a GET request should not make changes on the server (whereas POSTs can).

This is actually a good way to think, anyway. People that have browser accelerators that prefetch URLs will have lots of problems if GET type URLs are prefetched and if those URLs actually make a change on the server. Imagine prefetching 100s of URLs that are actually 'Delete this Entry' type URLs!
Im till learning aswell lol thanks for the info.
 
0
•••
PHP:
  <?php 

$name = $_GET['name'];

echo 'Thank you $name for soemthing bla bla';

?>
Would echo Thank you $name for soemthing bla bla. You would need to use double quotes or [..] you ' . $name . ' for [..] to make it actually say the name.
 
0
•••
Dan said:
PHP:
  <?php 
$name = $_GET['name'];
echo 'Thank you $name for soemthing bla bla';
?>
Would echo Thank you $name for soemthing bla bla. You would need to use double quotes or [..] you ' . $name . ' for [..] to make it actually say the name.
I think that depends on php.ini settings. I forget the setting, but if is enabled, you can stick variable names inside strings and they will be parsed. (It's horrible though)
 
0
•••
Forget the INI settings. If you want variables to be parsed in strings, use double quoted strings.

Double quoted strings parse variables while single quoted ones don't. Don't rely on changes to PHP.INI unless you have to...
 
0
•••
yh i found that out as well iv been reading about php alot of php.net and w3school so i got the hang of most of it now. it would be like this:

<?php

$name = $_GET['name'];

echo 'Thank you '.$name.' for soemthing bla bla';

?>

and that would print 'Thank you name for something bla bla.
 
0
•••
yes NetworkTown.Net that is another method to insert a variable into a string. That method is called concatenation. Some people prefer 1 method over the other I personally prefer concatenation over variables in double quotes as it is easier for me to see.
 
0
•••
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back