The Login Form
As the start page for our application, we will show a login form asking users for their username and password. The HTML source for the login form is show below, and Figure 15-2 shows the page rendered in a web browser:
<html> <head> <title>Jack and Jill's Wedding Gift Registry</title> </head> <body bgcolor='LIGHTBLUE'> <h2>Jack and Jill's Wedding Gift Registry</h2> (if you've not logged in before, make up a username and password) <form action="process.php" method="POST"> <br />Please enter a username: <input type="text" name="username" /> <br />Please enter a password: <input type="password" name="password" /> <br /><input type="submit" value="Log in" /> </form> </body> </html>
Figure 15-2. The wedding registry login page
When the user types in information and clicks the Submit
button, the form passes the data to the script specified in the form
action
attribute; in our example,
the data is sent to the script process.php.
Our form has three input fields: username
, password
, and submit
. Since the form submits the data
using the POST
method, we can look
inside the $_POST
superglobal array
in process.php
to access the
corresponding values as $_POST["username"]
, $_POST["password"]
, and $_POST["submit"]
. The data from the submit
field will just be Log In
(as
specified in the form), and this field isn’t very useful; however,
it’s important to know that it exists.
Using One Script ...
Get Learning MySQL now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.