PDA

View Full Version : $_post


aztek
07-14-2006, 05:04 AM
Hi Guys,

I'm new to PHP and bought a book i came to this part of the book that was'nt discussed well.

$title = $_POST['Submit']." ".$_POST['type']." : ".$_POST['Name'];

Can you explain this script or point me to a topic on the web. All help is appreciated.

Thanks and have a good day.

Brandoe85
07-14-2006, 05:14 AM
Hi,

$_POST is a superglobal where you can access your form variables. Example, you have a form with elements named Submit, type and Name. Now you can access their values through $_POST['Name'] etc...
Reference to this is:
http://us3.php.net/variables.predefined

Also, the '.' is the concatenation operator.

Good luck :)

dylan.lindgren
07-14-2006, 05:16 AM
Hi Guys,

I'm new to PHP and bought a book i came to this part of the book that was'nt discussed well.

$title = $_POST['Submit']." ".$_POST['type']." : ".$_POST['Name'];

Can you explain this script or point me to a topic on the web. All help is appreciated.

Thanks and have a good day.

IE, if you had a form that submitted values:
Submit: True
Type: Person
Name: Dylan

the code you posted up would set the variable $title to the following:

True Person : Dylan

That code confused me at first, because I always put spaces between variables im concatenating to make it easier to read. Also it makes it a little easier to read (although you get more lines of code) if you do it like this:



$submit = $_POST['Submit'];
$type = $_POST['type'];
$name = $_POST['Name'];

$title = $submit . " " . $type . " : " . $name;

You'll probably end up doing error checking on the $_POST variables anyway, so this would be the best way to do it.

Hope this helps
Dylan.

aztek
07-14-2006, 09:27 AM
Thanks a lot Brandoe85 & Dyla.lindgen your help was so appreciated.