Quote:
Originally Posted by Lee (i dont use id="" all that much, i use name="") |
id is important to use if you want to use a scripting language like javascript to access information on the page through the DOM. name is important to use for submitting data as the value of name will be the new variable on the server when the form is submittted.
Now, let's look at
Code:
<form action="handlefile.php">
<input type="text" id="username">
</input>
<input type="submit" id="password">
</input>
</form>
First, rewrite it as
Code:
<form action="login.php" method="post">
<input type="text" id="username" name="username" /><br />
<input type="password" id="password" name="password" /><br />
<input type="submit" value="Login" />
</form>
Then, assuming that form is also on login.php, you can access the username and password through $_POST['username'] and $_POST['password'], respectively. Here's an example.
PHP Code:
<?php
if (strlen($_POST['username']) > 0 && strlen($_POST['password']) > 0) {
// verify username and password
if ($_POST['username'] == "allowed_username" && $_POST['password'] == "password") {
//Take login action
} else {
//Take invalid login action
}
}
?>
<form action="login.php" method="post">
<input type="text" id="username" name="username" /><br />
<input type="password" id="password" name="password" /><br />
<input type="submit" value="Login" />
</form>