Introduction to Form
The <input type="text"> tag is a text box, while <input type="submit"> creates a submit button for sending web page back to the web server.
Example: 1
index.php
<html>
<head>
<title></title>
</head>
<body>
<form action ="loginTest.php" method="post">
Name: <input type ="text" name="name"/>
<input type="submit"/>
</form>
</body>
</html>
<html>
<head>
<title></title>
</head>
<body>
<form action ="loginTest.php" method="post">
Name: <input type ="text" name="name"/>
<input type="submit"/>
</form>
</body>
</html>
Output
When we click submit button, nothing happens. Because in our loginTest.php is a blank or not exist yet that does not give any actions or directions or anything.
Example: 2
index.php
<html>
<head>
<title></title>
</head>
<body>
<form action ="loginTest.php" method="post">
Name: <input type ="text" name="name"/>
<input type="submit"/>
</form>
</body>
</html>
<html>
<head>
<title></title>
</head>
<body>
<form action ="loginTest.php" method="post">
Name: <input type ="text" name="name"/>
<input type="submit"/>
</form>
</body>
</html>
loginTest.php
<html>
<body>
<html>
<body>
<?php
echo $_POST["name"];
echo $_POST["name"];
?>
</body>
</html>
</html>
Output
Whenever we click submit button, control goes to the loginTest.php.
$_POST indicates that getting the information from a form and not a normal variable.
If you don’t write method="post", then it looks for a variable on the same page. i.e., by making $_POST, is going to look variable on another page.
echo $_POST["name"] says, we want to echo something from a form, whatever the input for the name variable.
$_POST indicates that getting the information from a form and not a normal variable.
If you don’t write method="post", then it looks for a variable on the same page. i.e., by making $_POST, is going to look variable on another page.
echo $_POST["name"] says, we want to echo something from a form, whatever the input for the name variable.