Hi everyone

can anybody give me detail information about mission of $_post and $_get and differences between these functions?

Also can you give me information about forms and user inputs in php code?

Thank you

Member Avatar for rajarajan2017

Let see with the example to understand clearly:
input.html

<html>
<head></head>
<body> 
<form action="testing.php" method="post">
Enter your message: <input type="text" name="msg" size="30"> 
<input type="submit" value="Send"> 
</form> 
</body> 
</html>

testing.php

<html> 
<head></head>
<body> 

<?php 
// retrieve form data 
$input = $_POST['msg'];
// use it
echo "You said (POST): <i>$input</i>";

//you should change the method in html to "get"
$input1 = $_GET['msg'];
echo "<br/>You said (GET) : <i>$input1</i>"; 
?> 
</body> 
</html>

Post will transfer your elements values to other pages you want. Samething happen with Get, but it will transfer the elements thru url query string.

In the above example when sending with post check ur URL (nothing added) when sending with GET you can see the differnce in URL.

Both the purposes are same to transfer values from one page to other.

$_POST is a superglobal array that contains the values of the submitted for,.
$_GET is a superglobal array that contains the values of the url.

in order to check the submmited data from any form you can use this code:

echo nl2br(print_r($_POST,1));

similiary you can check the values of $_GET using this line of code:

echo nl2br(print_r($_GET,1));

A word on usage:
You should use $_POST for submitting forms, and $_GET when you need to redirect someone to a site an provide specific variable-value pairs. For example, if you have an e-commerce site, and your page loads product information from a database based on product ID numbers, you could have a link like:

<a href="http://www.mysite.com/products.php?id=<?=$product_id?>">View this product</a>

And then you would retrieve this variable in products.php with:

$product_id = (int) htmlentities(trim($_GET['id']));

You should not use GET as the action attribute to submit forms, especially not if the form contains sensitive information.

this code looks not good. i prefer using zf for cleaning income data

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.