douzhi9478 2011-06-27 23:02
浏览 18
已采纳

PHP帮助,不知道为什么这不起作用

So i have a username and password form posting data to this process.php file. But the error in trap in my code is suggesting something is wrong with the mysql query: "The username and password don't match. We will take you back to the login page in two seconds."

The md5 is working correctly and i have checked the data base tables all the rows are in there and how it should be. Any suggestions? Thanks Dave.

<?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');
}

?>
  • 写回答

3条回答 默认 最新

  • dongtangxi1584 2011-06-27 23:06
    关注

    Change this line:

    if(mysql_num_rows($client_data) == 1) {

    to

    if(mysql_num_rows($client_query) == 1) {

    mysql_num_rows() requires direct results of a mysql_query() call.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 simulink单相桥式整流电路
  • ¥35 问问51单片机流水灯的代码该怎么写
  • ¥15 关于#百度#的问题:感觉已经将字体段落、字体、页边距、纸张大小、文档网络调成与论文模板一致,为什么黄色部分字体左右的间距还是不一样啊,求私信发文件接收看一下
  • ¥15 stata webuse报错
  • ¥15 TypeError: Cannot read properties of undefined (reading 'status')
  • ¥15 如何利用AI去除图片中的竹架子
  • ¥15 python 写个基金爬取的代码,自动卖出功能
  • ¥15 Linux系统启动不起来
  • ¥15 为什么运行仿真数码管不亮(语言-c语言)
  • ¥15 陈仁良《直升机飞行动力学》小扰动线化方程如何推导