[advanced search]
Results from the most recent live auction are here.
26 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 10-26-2006, 03:13 AM   · #1
NetworkTown.Net
Senior Member
 
Name: Soon....
Location: United Kingdom
Trader Rating: (27)
Join Date: Oct 2005
Posts: 1,550
NP$: 49.74 (Donate)
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

$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

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.


Please register or log-in into NamePros to hide ads
__________________
PHP2k.com - PHP Coder[B]
NetworkTown.Net is offline   Reply With Quote
Old 10-26-2006, 05:09 AM   · #2
TwistMyArm
NamePros Member
 
Trader Rating: (0)
Join Date: May 2006
Posts: 157
NP$: 81.00 (Donate)
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   Reply With Quote
Old 10-26-2006, 09:54 AM   · #3
NetworkTown.Net
Senior Member
 
Name: Soon....
Location: United Kingdom
Trader Rating: (27)
Join Date: Oct 2005
Posts: 1,550
NP$: 49.74 (Donate)
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.
__________________
PHP2k.com - PHP Coder[B]
NetworkTown.Net is offline   Reply With Quote
Old 11-04-2006, 05:37 PM   · #4
Dan
Buy my domains.
 
Dan's Avatar
 
Name: Dan
Trader Rating: (63)
Join Date: Feb 2006
Posts: 2,800
NP$: 54.00 (Donate)
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   Reply With Quote
Old 11-04-2006, 05:56 PM   · #5
Jim_
NamePros Regular
 
Jim_'s Avatar
 
Name: Jim, of course
Location: Philadelphia
Trader Rating: (20)
Join Date: Aug 2005
Posts: 558
NP$: 14.30 (Donate)
Jim_ is a glorious beacon of lightJim_ is a glorious beacon of lightJim_ is a glorious beacon of lightJim_ is a glorious beacon of lightJim_ is a glorious beacon of light
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)
__________________
woop woop
Jim_ is offline   Reply With Quote
Old 11-05-2006, 04:15 AM   · #6
TwistMyArm
NamePros Member
 
Trader Rating: (0)
Join Date: May 2006
Posts: 157
NP$: 81.00 (Donate)
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   Reply With Quote
Old 11-05-2006, 06:51 AM   · #7
NetworkTown.Net
Senior Member
 
Name: Soon....
Location: United Kingdom
Trader Rating: (27)
Join Date: Oct 2005
Posts: 1,550
NP$: 49.74 (Donate)
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.
__________________
PHP2k.com - PHP Coder[B]
NetworkTown.Net is offline   Reply With Quote
Old 11-05-2006, 04:36 PM   · #8
Peter
NamePros Staff
 
Peter's Avatar
 
Name: Peter McDonald
Location: Dundee, Scotland
Trader Rating: (41)
Join Date: Nov 2003
Posts: 3,914
NP$: 1414.60 (Donate)
Peter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud ofPeter has much to be proud of
Child Abuse Save The Children Save The Children
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   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


Site Sponsors
Buy Flash Arcade Game Script Proof is in the Parking Proof is in the Parking
Advertise your business at NamePros
All times are GMT -7. The time now is 02:34 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0