Botturn PHP Programing

All About PHP, Tutorials, Scripts, Video Lessons, Forum, Downloads


TUTORIAL - Understanding $ _GET and $ _POST in PHP

Posted by admin On March - 16-2009

Probably you think make a website in php will certainly need to use $ _POST and $ _GET, because you will need to carry variables from page to page.

So I'll give a brief explanation of how these two methods of transport variables.
We start with the $ _POST:

In a website often have forms, or to register members, login system, contacts, etc.. To save the fields filled by HTML. In this practical example we will see how it works:

Creation of user registration form:

? Download test.php
  "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" > <! DOCTYPE html PUBLIC "- / / W3C / / DTD XHTML 1.0 Transitional / / EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 "http://www.w3.org/1999/xhtml" > <Html xmlns = "http://www.w3.org/1999/xhtml">
 <Head>
 equiv = "Content-Type" content = "text/html; charset=utf-8" /> <Meta http - equiv = "Content-Type" content = "text / html; charset = utf-8" />
 Tutorial $_POST BOTTURN . COM </ title > <Title> $ _POST BOTTURN Tutorial. COM </ title>
 </ Head>

 <Body>

 "0" cellspacing = "0" border = "0" > <Table cellpadding = "0" cellspacing = "0" border = "0">
	 <Tr>
    	 <Td>
             "teste.php" method = "post" enctype = "multipart/form-data" > <Form action = "test.php" method = "post" enctype = "multipart / form-data">
             "0" cellspacing = "0" border = "0" > <Table cellpadding = "0" cellspacing = "0" border = "0">
                 <Tr>
                     Nome :</ td > <Td> Name: </ td>
                     input type = "text" name = "nome" id = "nome" /></ td > <Td> <input type = "text" name = "Name" id = "name" /> </ td>
                 </ Tr>
                 <Tr>
                     Email :</ td > <Td> Email: </ td>
                     input type = "text" name = "email" id = "email" /></ td > <Td> <input type = "text" name = "email" id = "email" /> </ td>
                 </ Tr>
                 <Tr>
                     Descrição :</ td > <Td> Description: </ td>
                     textarea name = "descricao" id = "descricao" cols = "45" rows = "5" ></ textarea ></ td > <Td> <textarea name = "description" id = "description" cols = "45" rows = "5"> </ textarea> </ td>
                 </ Tr>
                 <Tr>
                     input type = "submit" value = "Enviar" /></ td > <Td> <input type = "submit" value = "Submit" /> </ td>
                 </ Tr>
             </ Table>
             </ Form>
        </ Td>
    </ Tr>
 </ Table>
 <Br />
 <? PHP
 $_POST ) { if ($ _POST) {

	 "Nome: " . $_POST [ 'nome' ] . "<br>" ) ; echo ("Name:". $ _POST ['name']. "<br>");
	 "Email: " . $_POST [ 'email' ] . "<br>" ) ; echo ("Email". $ _POST ['email']. "<br>");
     "Descrição: " . $_POST [ 'descricao' ] . "<br>" ) ; echo ("Description". $ _POST ['description']. "<br>");

 }

 ?>
 </ Body>
 </ Html> 

The method $ _GET variable is used to receive through the URL (Link to insert in your browser), have certainly seen in some sites a link this way www.exemplo.com/index.php?x=1.
Then we will begin by explaining the syntax:

exemplo.php?
The point of? is the way to declare that the following are variable.

exemplo.php? x = 1
After? we can begin to declare variables. In this example we are setting the variable x with value 1.

exemplo.php? & x = 1 y = 2
We can declare more than one variable, you just put & loved variables.

Now we will see an example that will write on the page variable received via $ _GET.

? Download exemploGet.php
  <? PHP
 $_GET [ "x" ] ; $ Variable = $ _GET ["x"];

 $variavel ) { if ($ variable) {
          . $variavel ; echo "The variable X contains." $ variable;
 { Else {}
          " echo "There no variables passed via $ _GET"
 }
 ?>
 / / Download the file and test the following is exemploGet.php? X = Value 

And that this tutorial is finished, we learned that the $ _POST variable is used to move through forms and $ _GET via the URL.

Popularity: 15% [ ? ]

Related posts Brought to you by Yet Another Related Posts Plugin .

3 Responses to "TUTORIAL - Understanding $ _GET and $ _POST in PHP"

  1. softclean says:

    Although not find a good policy mix POST and GET on the same page, is a funny example of reference for anyone who uses the $ _REQUEST know what will get the same variables that are sent by POST and GET:

    <Php
    echo "POST {$ _POST ['data']}";
    echo "GET {$ _GET ['data']}";
    echo "REQ {$ _REQUEST ['data']}";
    ?>

    Notice that the address sends POST data and GET form with the same value of the variable. The interest is to see what value is the variable $ _REQUEST ['data']

  2. softclean says:

    in the example above, a failure to put HTML form with a text field with the name 'data' and the address where the form is points 'pagina.php? porget data ='

    There has to put in the example above.

  3. admin says:

    Register and you as a meth-editor, and thus you can insert your tutorials here! You'd be very welcome! =)

Leave a Reply