所以我有一个用户名和密码表格将数据发布到这个process.php文件。但是我的代码陷阱中的错误表明mysql查询有问题:“用户名和密码不匹配。我们将在两秒钟内将您带回登录页面。”
md5工作正常,我检查了数据库表中的所有行以及它应该是什么。有什么建议?谢谢戴夫。
<?php
//Code DavidMaitland.me 2011
//Process data from the login form
require('database.php');
$username = mysql_real_escape_string($_POST["username"]);
$password = mysql_real_escape_string(md5($_POST["password"]));
$client_query = mysql_query("SELECT * FROM clients WHERE client_username='$username' and client_password='$password'") or die (mysql_error());
$client_data = mysql_fetch_array($client_query, MYSQL_ASSOC);
if(mysql_num_rows($client_data) == 1) {
session_start();
$_SESSION['client_id'] = $client_data['id'];
header('Location: account.php');
} else {
echo "The username and password don't match. We will take you back to the login page in two seconds.";
header('Refresh: 2; url=index.php');
}
?>
答案 0 :(得分:6)
更改此行:
if(mysql_num_rows($client_data) == 1) {
到
if(mysql_num_rows($client_query) == 1) {
mysql_num_rows()需要mysql_query()
来电的直接结果。
答案 1 :(得分:1)
您需要使用mysql_num_rows($client_query)
代替mysql_num_rows($client_data)
。
答案 2 :(得分:1)
更改此部分
if(mysql_num_rows($client_query) == 1) {
session_start();
$_SESSION['client_id'] = $client_data['id'];
header('Location: account.php');
} else {
echo "The username and password don't match. We will take you back to the login page in two seconds.";
header('Refresh: 2; url=index.php');
}
由于您在获取的数组上通过mysql_num_rows计算行数,因此您应该在资源上计算它($ client_query)