Skip to content

Instantly share code, notes, and snippets.

@biplab3
Created April 11, 2020 12:47
Show Gist options
  • Save biplab3/67afd2ec97ab12cd47ac77cd4c25b3cd to your computer and use it in GitHub Desktop.
Save biplab3/67afd2ec97ab12cd47ac77cd4c25b3cd to your computer and use it in GitHub Desktop.
<html>
<body>
<form method="post" action="<?php echo $_SERVER['PHP_SELF'];?>">
Name: <input type="text" name="username">
<input type="submit" name="save" value="submit">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// collect value of input field
$username = $_REQUEST['username'];
if (empty($username)) {
echo "Username is empty";
} else {
echo $username;
}
}
?>
</body>
</html>
or
<html>
<body>
<form method="post" action="">
Name: <input type="text" name="username">
<input type="submit" name="save" value="submit">
</form>
</body>
</html>
<?php
if (isset($_POST['save']) //here 'save' is the name attribute of the button field
{
// collect value of input field
$username = $_POST['username'];//here username is the field name of the input type element
echo $username;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment