Tuesday, March 20, 2012

PHP basic function: $_GET



 $_GET allows values to be read in through the page URL (e.g. index.php?name=jiansen) or collect values in a form.
For example, in  index.php?name=jiansen
 $myname =$_GET['name'];
assign  the value jiansen to $myname
Use with form using $_GET:
<form method="get" action="<?php echo $_SERVER['PHP_SELF']; ?>">
   <input type="text" name="name"><br>
   <input type="submit" name="submit" value="Submit Form"><br>
</form>
<?php
$myname=$_GET['name'];
if(isset($myname)) echo 'My name is '.$myname;
?>
 The difference between $_REQUEST, $_GET and $_POST
$_GET retrieves variables from the query string, or your URL.
$_POST retrieves variables from a POST method, such as (generally) forms.
$_REQUEST is a merging of $_GET and $_POST where $_POST overrides $_GET. Good to use $_REQUEST on self referential forms for validations.

Video: PHP Basics: $_GET

No comments:

Post a Comment