PHP - MySQL Why is this query never returning false? -



PHP - MySQL Why is this query never returning false? -

i'm busy php/mysql login system, fun. made function:

function login($username, $password) { $user_id = user_id_from_username($username); $password = md5($password); homecoming (mysql_result(mysql_query("select count (`user_id`) `users` `username` = '$username' , `password` = '$password'"), 0) == 1) ? $user_id : false;

but reason returns user_id, never false, when login credentials wrong!

function login($username, $password) { //$user_id = user_id_from_username($username); // remove line downwards if statement $password = md5($password); $query = mysql_query("select `username`, `password` `users` `username` = '$username' , `password` = '$password'"); // check if query success if($query) { // check if there user matching info if(mysql_num_rows($query) > 0) { $user_id = user_id_from_username($username); // here. called when credentials right homecoming true; } else { homecoming false; } } }

but should start useing mysqli_* or pdo, mysql_* detracted. don't trust md5() cracked. utilize hash('sha512', md5($password));

try following:

$result = mysql_query("select `active` `users` `username` = '$username'"); $return = mysql_result($result, 0); // should 0 or 1, don't know sure. need seek out // if query success if($result) { if ($return > 0 && $return < 3) { homecoming true } else { homecoming false; } } http://php.net/manual/en/function.mysql-result.php

php mysql

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -