User Authentication
Posted: Wed Nov 26, 2003 1:33 pm
Hi,
I created a database with the table 'user' using MySQL. What I wanted to do is when the user logged in with the user name and password and submit it should check the database to check if the user exist or not. However when I enter valid username and password and click on submit all I see is a blank page. Can you help me please here is my login.html and login.php
<HTML>
<HEAD>
<TITLE>Login Form</Title>
</HEAD>
<!-- Configure the form -->
<BODY>
<FORM ACTION="login.php" METHOD="post">
<table border=0>
<tr>
<td><strong>Username</strong></td>
<td><input type="text" name="username" size="10" maxsize="10"></td>
</tr>
<tr>
<td><strong>Password</strong></td>
<td><input type="password" name="password" size="10" maxsize="10"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="submit">
</td>
</tr>
</table>
</FORM>
</BODY>
</HTML>
and login.php
---------------------------------------------------------------------------
Thanks again for your help
I created a database with the table 'user' using MySQL. What I wanted to do is when the user logged in with the user name and password and submit it should check the database to check if the user exist or not. However when I enter valid username and password and click on submit all I see is a blank page. Can you help me please here is my login.html and login.php
<HTML>
<HEAD>
<TITLE>Login Form</Title>
</HEAD>
<!-- Configure the form -->
<BODY>
<FORM ACTION="login.php" METHOD="post">
<table border=0>
<tr>
<td><strong>Username</strong></td>
<td><input type="text" name="username" size="10" maxsize="10"></td>
</tr>
<tr>
<td><strong>Password</strong></td>
<td><input type="password" name="password" size="10" maxsize="10"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="submit">
</td>
</tr>
</table>
</FORM>
</BODY>
</HTML>
and login.php
---------------------------------------------------------------------------
Code: Select all
<?php
<?php //login.php
if(isset($_POST["submit"] )) {
// Open the database connection
$db=mysql_connect("localhost") or die ("Unable to connect to databse.");
mysql_select_db("authenticate") or die ("Unable to select database.");
$username = $_POST['username'];
$password = $_POST['password'];
// Formulate the query
$sql = "SELECT count(*)
FROM user
WHERE username='$username' and password='$password'";
// Execute the query and put results in $result
$result = mysql_query($sql) or die ("Couldn't get reults.");
//Get number of rows in $result. Should be 0 if invalid, 1 if valid.
$count = mysql_result($result,0,0);
// Present results based on validity.
if ($count == 1) {
echo "<P>You are a valid user!<br>";
}
else if ($count == 0) {
echo "You are not authorized!";
}
}
?>
?>