bindParam 与 md5() 列 PDO PHP
bindParam with md5() column PDO PHP
我尝试比较数据库中的用户密码和来自登录表单的用户密码,但是当我这样做时:
$stmt = $dbh->prepare('SELECT * FROM users WHERE (username = :username, password = :password)');
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', md5($_POST['password']));
$stmt->execute();
$stmt->fetch(); // return false
我做错了什么?
你应该这样写你的查询:
SELECT * FROM users WHERE (username = :username AND password = :password)
您的查询有误。
试试这个:
$stmt = $dbh->prepare('SELECT * FROM users WHERE username = :username AND password = :password');
正确查询。使用下面的代码
$stmt = $dbh->prepare('SELECT * FROM users WHERE username = :username AND password = :password');
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', md5($_POST['password']));
$stmt->execute();
$stmt->fetch(); // return false
希望对您有所帮助
我尝试比较数据库中的用户密码和来自登录表单的用户密码,但是当我这样做时:
$stmt = $dbh->prepare('SELECT * FROM users WHERE (username = :username, password = :password)');
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', md5($_POST['password']));
$stmt->execute();
$stmt->fetch(); // return false
我做错了什么?
你应该这样写你的查询:
SELECT * FROM users WHERE (username = :username AND password = :password)
您的查询有误。 试试这个:
$stmt = $dbh->prepare('SELECT * FROM users WHERE username = :username AND password = :password');
正确查询。使用下面的代码
$stmt = $dbh->prepare('SELECT * FROM users WHERE username = :username AND password = :password');
$stmt->bindParam(':username', $_POST['username']);
$stmt->bindParam(':password', md5($_POST['password']));
$stmt->execute();
$stmt->fetch(); // return false
希望对您有所帮助