Explain $_GET and $_POST superglobal arrays

Explain $_GET and $_POST superglobal arrays


Explain $_GET and $_POST superglobal arrays

Answer

$_GET

  • $_GET is a superglobal variable used to collect data from the HTML form after submitting it.
  • When form uses method get to transfer data, the data is visible in the query string therefore the values are not hidden.
  • $_GET superglobal array variable stores the values that come in the URL

EXAMPLE:

<html>
<head></head>
<body>
<form method="get">
<input type="text" name="name"> your name<br>
<input type="text" name="city">your city<br>
<input type="submit" name="submit">Submit
<?php
if(isset($_GET['submit']))
{
$name = $_GET['name'];
$city = $_GET['city'];
echo "<h1>This is".$name."of".$city."</h1>";
}?>
</body>
</html>

$_POST

  • $_POST is a superglobal variable used to collect data from the HTML form after submitting it.
  • When form use method post to transfer data, the data is not visible in the query string, so it is more secure than $_GET method.
Example

<html>
<head></head>
<body>
<form method="post">
<input type="text" name="name"> your name<br>
<input type="text" name="city">your city<br>
<input type="submit" name="submit">Submit
<?php
if(isset($_POST['submit']))
{
$name = $_POST['name'];
$city = $_POST['city'];
echo "<h1>This is".$name."of".$city."</h1>";
}?>
</body>
</html>

Similar concept Video tutorial


Other Question With Answer


















No comments:

For Query and doubts!

Powered by Blogger.