简体   繁体   中英

Function doesn't work properly

I have this function in class called User

/**
* Function to get everything about specific user
* @access public
* @param string that user's email
* @param string that user's password
*/
public static function selectUser ( $email, $password )
{
    $result = mysql_query ( ' SELECT * FROM `modernt_mtalk`.`users` WHERE Email = ' . $email . ' AND Password = ' . md5($password) );

    if($result) {return $result;}
    else        {return false;}
}

and i call it in other file

require_once 'user.php';
$user = new User();

$info = $user -> selectUser('baronas15@gmail.com', 'root');

echo $info;

I put that data in so i can test if echo $info would give me anything. but that echo does nothing.

I know that it's not wrong data in () because i have other function that i tested with the same data and it works fine. What's wrong?

Here's how you call a static function, you shouldn't encrypt the parameter since the function already does this for you:

$info = User::selectUser('baronas15@gmail.com', 'root'); //no need to encrypt twice

Also the query doesn't look correct, since email and password are not integers, they will need to be quoted:

$result = mysql_query ("SELECT * FROM `modernt_mtalk`.`users` WHERE Email = '". $email ."' AND Password = '". md5($password)."'");

That's because you parse already encrypted password which I suspect you shouldn't encrypt since you also encrypt it in your query so the method returns false. var_dump the result or display the "incorrect logins" if the method returns false

require_once 'user.php';
$user = new User();

if($info = $user -> selectUser('baronas15@gmail.com', 'root'))
     echo $info;
else
     echo 'Incorrect details';

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM