Posted by Yavuz S. Atmaca on 04/29/05 18:50
Hi all
I'm trying to do authentication with database. I
created the database and I inserted some usernames and
passwords into my database. By using the below file,
I'm trying to give access to the main page for the
accounts that matches the username and password. The
problem is that "it do not recognize the usernames and
password that i already inserted and it dont let me
in.
Do you see an problem with the code ort any idea?
When I modifiy that line to 0, it lets me in
if (mysql_num_rows($result) ==0) //--->like
that
Thanks in advance :)
------------This is my form and php file--------------
<?php
session_start();
$errorMessage = '';
if (isset($_POST['txtUserId']) &&
isset($_POST['txtPassword'])) {
include 'library/config.php';
include 'library/opendb.php';
$userId = $_POST['txtUserId'];
$password = $_POST['txtPassword'];
// check if the user id and password combination
exist in database
$sql = "SELECT user_id
FROM tbl_auth_user
WHERE user_id = '$userId' AND
user_password = PASSWORD('$password')";
$result = mysql_query($sql) or die('Query failed.
' . mysql_error());
if (mysql_num_rows($result) ==1) {
// the user id and password match,
// set the session
$_SESSION['db_is_logged_in'] = true;
// after login we move to the main page
header('Location: main.php');
exit;
} else {
$errorMessage = 'Sorry, wrong user id /
password';
}
include 'library/closedb.php';
}
?>
<html>
<head>
<title>Basic Login</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1">
</head>
<body>
<?php
if ($errorMessage != '') {
?>
<p align="center"><strong><font color="#990000"><?php
echo $errorMessage; ?></font></strong></p>
<?php
}
?>
<form action="" method="post" name="frmLogin"
id="frmLogin">
<table width="400" border="1" align="center"
cellpadding="2" cellspacing="2">
<tr>
<td width="150">User Id</td>
<td><input name="txtUserId" type="text"
id="txtUserId"></td>
</tr>
<tr>
<td width="150">Password</td>
<td><input name="txtPassword" type="password"
id="txtPassword"></td>
</tr>
<tr>
<td width="150"> </td>
<td><input name="btnLogin" type="submit"
id="btnLogin" value="Login"></td>
</tr>
</table>
</form>
</body>
</html>
------------------------------------------------------
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
[Back to original message]
|