problem with my login table

A

Anonymous

Guest
Hi guys,

I created a login table in mysql, only two colums: user_name and user_pwd.

Two problems:

1. if table only has one row: user has to type twice correct user_name and user_pwd, then can login.

2. if table has one more row, user cant login, even with correct user_name and user_pwd.

my php coding must has problems, please help me to find out, thanx

<?php
$result = mysql_query("select * from user_access")
or die(mysql_error());

while ($row = mysql_fetch_array($result) AND TRUE)
{
if (strcmp($_POST['user_name'], $row["user_name" ])!= 0 AND $_POST['user_pwd']!= $row["user_pwd"] )
{

print ("<font color='red' size='3'><center><strong>Password or Username are not correct!Please try again</strong></center></font>");


return FALSE;
//exit;
}
}


print ("<font color='green' size='3'><center><strong>Welcome to visit our products!</strong></center></font>");


?>
 
Take a look at this!
Example:
Code:
<?php

$username = trim($_POST['user_name']);
$password = md5(trim($_POST['user_pwd']));

$result = mysql_query("SELECT id FROM user_access WHERE usr = '$username' AND pwd = '$password'");
// Note that the password was already stored with MD5 hash.

if(mysql_num_rows($result) == 0) {
     print 'Login error!';
     die();
}

// do the login stuff here
// Example: 

$row = mysql_fetch_array($result);
$_SESSION['username'] = $row[usr];

// ...

?>
 
Back
Top