PHP Tutorial : Forms processing with $_POST or $_GET

Are you just curious to know the difference between $_GET and $_POST php server variables? Errrr, let me try and explain. I dont see many differences, or maybe I dont know/explain, but what I understand it is that $_POST it’s used in most of the cases because security, and $_GET will show your entered forms fields values into the url. For example :

<form action="" method="POST">
Your field value here <input type="text" name="fieldname">
<input type="submit" name="sb" id="sb" value="Go">
</form>
<?php
//check if form was sent


if(isset($_POST['sb'])) {
print $_POST['fieldname'];
}
//this with post will not show values into url

?>
<form action="" method="GET">
Your field value here <input type="text" name="fieldname">
<input type="submit" name="sb" id="sb" value="Go">
</form>
As for get, you will see after you submit your form that value entered will showup in url
<?php

if(isset($_GET['sb'])) {
print $_GET['fieldname'];
}
//and check your url, if you make a forms.php page, and hit submit you'll see //forms.php?fieldname=whatyouentered&amp;sb=Go

?>
This entry was posted in Basic PHP and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>