Recently started learning php and am trying to get the get method to work.
This is the html form I am testing on:
<!DOCTYPE html>
<html>
<body>
<form action="foo.php" method="get">
Name: <input type="text" name="username" /><br />
Email: <input type="text" name="email" /><br />
<input type="submit" name="submit" value="Submit me!" />
</form>
</body>
</html>
I researched and found that you should use isset() to check if the $_GET array contains the value. So I tried(this is foo.php):
<?php
if(isset($_GET['username']))
{
echo $_GET['username'];
}
else
{
echo "username not passed <br />";
}
if(isset($_GET['email']))
{
echo $_GET['email'];
}
else
{
echo "email not passed";
}
?>
It seems something is wrong with trying to pass the values via the get method, I tried the exact same thing with post, replacing method="get" to method="post" and changing $_GET to $_POST in the php file. This worked perfectly with the post method. I know you shouldn't pass sensitive information like email etc via the get method but i am just trying to test it out.
This is the output I get after I submit the form: username not passed email not passed