所以我有一个用户名和密码表单将数据发布到这个 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');
}
?>
最佳答案
改变这一行:
if(mysql_num_rows($client_data) == 1) {
到
if(mysql_num_rows($client_query) == 1) {
mysql_num_rows()需要 mysql_query()
调用的直接结果。
关于PHP 帮助,不确定为什么这不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6499943/