我是mysql和php的新手。用户使用php和mysql数据库登录
一直在为用户创建一个带有表的数据库。
我已经成功地将用户添加到数据库,他们的密码与md5(是的,我知道它不安全),它不会在线启动。
我的问题是,如何根据用户名和密码登录用户。
这里是我的代码
我的逻辑是taht查询运行后,它会返回true或false。
如果为true,则显示登录成功,否则不成功。
然而,即使我输入正确的用户名和密码,我仍然得到一个不成功的登录信息
我检查了MySQL数据库,以及uesrname是有正确
想法?
if(!empty($_POST['userLog']) && !empty($_POST['passLog']))
{
//set the username and password variables from the form
$username = $_POST['userLog'];
$password = $_POST['passLog'];
//create sql string to retrieve the string from the database table "users"
$sql = "SELECT * FROM `users` WHERE userName = '$username' AND password = md5('$password')";
$result = mysql_query($sql);
if ($result == true) {
$return = "<font color=#008000><Center><b>**Successful Login**</b></Center></font>";
} else {
$return = "<font color=#ff0000><Center><b>**Failed Login**</b></Center></font>";
}
print($return);
}
看起来像md5(密码)将成为qry字符串的一部分。尝试将其更改为'$ sql =“SELECT * FROM \'users \'WHERE userName ='$ username'AND password ='”.md5('$ password')。“'”;' – SchautDollar 2013-03-02 21:38:39
快速提示使用phpass - > http://www.openwall.com/phpass/ – Espen 2013-03-02 21:43:18