Username and Password Checker

That’s what’s wrong here, it tells me “Invalid Login or Password” Even if the password and Login are correct, what should I do? Thanks in advance)


Answer 1, authority 100%

In your code, two variables refer to the same $username


Answer 2

Can the password be stored in md5 in the database?


Answer 3

....
if(mysql_result(mysql_query("SELECT count(*) FROM $tbl_name WHERE username='$username' and password='$password'" LIMIT 1),0)==1)
{
    session_register("username");
    session_register("password");
    header("location:login_success.php");
} else {
    echo "   ";
}
....

Answer 4

The code works great. Option 2:

  1. something wrong is being passed to $_POST['username']or $_POST['password']
  2. or in the “members” table cant. By the way, can I see her dump?

Answer 5

Maybe the wrong connection? Specify it hard.

Maybe not $_POST?

Maybe there is a sign '

in the login-password

Maybe you should trim spaces, \rand \nfrom login and password?

Maybe the name of the table is incorrectly specified or some wrong characters pop up somewhere? It is worth ask the muscle itself about the error?

<?
// ...
error_reporting(E_ALL);
$DB = mysql_connect($host, $username, $password) or die("can't connect");
mysql_select_db($db_name, $DB) or die(mysql_error());
$username = $_POST['username'];  //   $_GET?
$password = $_POST['password'];  //   $_GET?
$username = trim($username);
$password = trim($password);
$username = mysql_real_escape_string($username, $DB);
$password = mysql_real_escape_string($password, $DB);
var_dump($username, $password);
$sql = "SELECT * FROM `" .$tbl_name. "` WHERE username='" .$username. "' and password='". $password. "'";
$result = mysql_query($sql, $DB);
echo '<pre>'.$sql.'</pre><p>'.mysql_error($DB).'</p>';
// ...
?>