-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
  • array(7) { ["id"]=> string(1) "3" ["fname"]=> string(4) "PRIVATE" ["lname"]=> string(6) "PRIVATE" ["email"]=> string(21) "PRIVATE@gmail.com" ["password"]=> string(8) "PRIVATE" ["hash"]=> string(32) "3d36c07721a0a5a96436d6c536a132ec" ["active"]=> string(1) "0" } – nestorishimo10 Oct 27 '14 at 21:30
  • Actually now neither of them work (neither passwod and active) – nestorishimo10 Oct 27 '14 at 21:30
  • So, where is your problem? var_dump shows, in $row['password'] is the password. – tkausl Oct 27 '14 at 21:31
  • Then you have some problems in other parts of your code, with fetch_assoc you get exactly what you want. – tkausl Oct 27 '14 at 21:32