-1

im making a social networking website (i will not tell my full idea yet) and i cant get login verification to work. This is my code:

mysql_connect("AHOST", "MYDATABASE", "PRIVACY");
mysql_select_db("u848966676_users");
$email = $_POST['email'];
$password = $_POST['code'];
$rs = mysql_query("SELECT * from `users` WHERE `email`='$email' LIMIT 1");
if(!$rs) die(mysql_error());
if(mysql_num_rows($rs) > 0) {
    $active = 0;
    while ($row=mysql_fetch_row($rs)) {
    $rp = $row['password'];
    $active = $row['active'];
    if($password != $rp) {
        die("<script>alert(\"Password is incorrect.$rp and $password\");</script>");
    }
}
if($active === 0) {
    echo "<script>alert(\"Account has not been verified.\");</script>";
                            } else {
                                $_SESSION['logged'] = true;
                                $_SESSION['email'] = $email;
                                header("Location: index.php");
                            }
                        } else {
                                echo "<script>alert(\"Account does not exist.\");</script>";
                        }

And my problem is that $rp is ""... its literally empty! But on phpMyAdmin is shows my password... :(

1 Answers1

0

mysql_fetch_row returns a numeric array, so you should use mysql_fetch_assoc for an assoziative array.

The mysql_ extension is deprecated and will be removed in the future, you should use mysqli_ or (better) PDO if you dont want to change everything later on.

tkausl
  • 13,686
  • 2
  • 33
  • 50