Working with html form, these form inputs can be access using php superglobal arrays $_GET and $_POST.
$_GET: This get the value from the web url after the '?' sign for example www.site.com?id=1
And if there is any space the system convert it to + sign for example www.site.com?name=Marshall+Unduemi&age=25;
$name = $_GET["name"]; // $name is "Marshall Unduemi"
$age = $_GET["age"]; // $age is 25
$_POST: for geting user data from html form using standard input this time the values passed along are un escaped.
Example www.site.com?name=Marshall+Unduemi&age=25;
$name = $_GET["name"]; // $name is "Marshall Unduemi"
$age = $_GET["age"]; // $age is 25
Is a best practice to avoid php warning and errors, the idea of using isset to check if the value passed is in $_POST OR $_GET method.
if (!isset($_POST["name"]) || trim($_POST["name"]) == "")
{
echo "The User's name was left blank.";
}
A shorcut to access variables in $_GET and $_POST: all you need to do is to extract $_POST OR $_GET all key/value pairs in identically
named variables for example
extract($_POST);
if (isset($name))
echo "Hello, $name!";
Hope this help you a little
$_GET: This get the value from the web url after the '?' sign for example www.site.com?id=1
And if there is any space the system convert it to + sign for example www.site.com?name=Marshall+Unduemi&age=25;
$name = $_GET["name"]; // $name is "Marshall Unduemi"
$age = $_GET["age"]; // $age is 25
$_POST: for geting user data from html form using standard input this time the values passed along are un escaped.
Example www.site.com?name=Marshall+Unduemi&age=25;
$name = $_GET["name"]; // $name is "Marshall Unduemi"
$age = $_GET["age"]; // $age is 25
Is a best practice to avoid php warning and errors, the idea of using isset to check if the value passed is in $_POST OR $_GET method.
if (!isset($_POST["name"]) || trim($_POST["name"]) == "")
{
echo "The User's name was left blank.";
}
A shorcut to access variables in $_GET and $_POST: all you need to do is to extract $_POST OR $_GET all key/value pairs in identically
named variables for example
extract($_POST);
if (isset($name))
echo "Hello, $name!";
Hope this help you a little
No comments:
Post a Comment