dongqi7631 2011-12-21 19:04
浏览 17
已采纳

我无法解决的SQL错误

i am new to php and do not know how to fix the following error:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in E:\webareas\hj942\CW\Website\Login\incorrect.php on line 15

I have a users table with a role that consists of a normaluser and a chairperson. I am trying to only select all from the users table where the role is normaluser. I am getting the error message above. My php code is as follows:

<?php
include("../includes/db.php");

$username=$_POST['username'];
$password=$_POST['password'];

$username = stripslashes($username);
$password = stripslashes($password);
$username = mysql_real_escape_string($username);
$password = mysql_real_escape_string($password);

$sql="SELECT * FROM Users WHERE username='$username' and password='$password' And role = normaluser";
$result=mysql_query($sql);

$count=mysql_num_rows($result);

if($count==1){
session_register("username");
session_register("password");
header("location:myaccount.php");
}

?>

Thank you very much for any help provided.

  • 写回答

3条回答 默认 最新

  • dsf12313 2011-12-21 19:07
    关注

    Try this:

    $sql="SELECT * FROM Users WHERE username='$username' and password='$password' And role = 'normaluser'";
    

    i.e: quoting the role value. See if that works...

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

报告相同问题?

悬赏问题

  • ¥20 易康econgnition精度验证
  • ¥15 线程问题判断多次进入
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致