NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page [Tutorial] on $_POST & $_GET

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search
7 members in live chat ~  


Closed Thread
 
LinkBack Thread Tools
Old 10-26-2006, 03:13 AM THREAD STARTER               #1 (permalink)
Account Suspended
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice
 



[Tutorial] on $_POST & $_GET


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 Code:
<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 Code:
<?php
????: NamePros.com http://www.namepros.com/code/251015-tutorial-on-_post-and-_get.html

$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 Code:
<?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
????: NamePros.com http://www.namepros.com/showthread.php?t=251015

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.
NetworkTown.Net is offline  
Old 10-26-2006, 05:09 AM   #2 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



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!
TwistMyArm is offline  
Old 10-26-2006, 09:54 AM THREAD STARTER               #3 (permalink)
Account Suspended
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice
 



Originally Posted by TwistMyArm
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.
NetworkTown.Net is offline  
Old 11-04-2006, 05:37 PM   #4 (permalink)
Dan
Buy my domains.
 
Dan's Avatar
Join Date: Feb 2006
Posts: 2,792
Dan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant futureDan has a brilliant future
 


Autism Autism Autism Autism Autism Autism Autism
PHP Code:
  <?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.
Dan is offline  
Old 11-04-2006, 05:56 PM   #5 (permalink)
NamePros Regular
 
Jim_'s Avatar
Join Date: Aug 2005
Location: NY, USA
Posts: 608
Jim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to beholdJim_ is a splendid one to behold
 


Save The Children
Originally Posted by Dan
PHP Code:
  <?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)
__________________
ask me about the internet
Jim_ is offline  
Old 11-05-2006, 04:15 AM   #6 (permalink)
NamePros Member
Join Date: May 2006
Posts: 160
TwistMyArm is on a distinguished road
 



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...
TwistMyArm is offline  
Old 11-05-2006, 06:51 AM THREAD STARTER               #7 (permalink)
Account Suspended
Join Date: Oct 2005
Location: United Kingdom
Posts: 1,554
NetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really niceNetworkTown.Net is just really nice
 



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.
NetworkTown.Net is offline  
Old 11-05-2006, 04:36 PM   #8 (permalink)
NamePros Expert
 
Peter's Avatar
Join Date: Nov 2003
Location: Scotland
Posts: 5,074
Peter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond reputePeter has a reputation beyond repute
 


Child Abuse Save The Children Save The Children Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
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.
Peter is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


 
All times are GMT -7. The time now is 03:09 PM.

Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger