PhoenixDown
Programmer
How do I check a username and password in a mysql database? I'm trying to make a user login form.
Follow along with the video below to see how to install our site as a web app on your home screen.
Note: This feature may not be available in some browsers.
the login page
----------------
<form action="doAuthuser.php" method="post" name="frmLogin">
<table bgcolor="Gainsboro" align="center" cellspacing="2" cellpadding="2" border="0">
<tr>
<th colspan="2" align="center">System Login</th>
</tr>
<tr>
<td><strong>UserName</strong></td>
<td><input type="text" name="frmLogin[username]" size="12" maxlength="12"></td>
</tr>
<tr>
<td><strong>Password</strong></td>
<td><input type="password" name="frmLogin[password]" size="12" maxlength="12"></td>
</tr>
<tr colspan="2">
<td align="left"><input type="submit" name="frmLogin[submit]" value="Login"></td>
<td align="right"><input type="Reset"></td>
</tr>
</table>
</form>
---------------
---------------
doAuthuser.php
-------------
<?php
// IF the login form was sent
if(isset($_POST['frmLogin']))
{
$sql = "SELECT username, password FROM auth_users WHERE username = '" .
$_POST['frmLogin']['username'] . "' AND password = '" . $_POST['frmLogin']['password'] ."'";
$result = mysql_query( $sql ) or die( mysql_error());
if(!$result)// if no match in DB
{
echo "No username or password matches your entry. Please register.";
/* ......redirect to registration page...... */
}else{
/*
do whatever you want to do for an authorized user here
like:
header("Location: pageOne.php");
*/
}
}else{
/*
* test if the user hits this page via the login form
* if test fails send them straight to login page
*/
header("Location: login.php");
}
?>
---------
---------