doulu1914 2013-12-18 03:00
浏览 24

警告:mysql_num_rows()期望参数1为资源,第27行的C:\ wamp \ www ovel \ loginadmin.php中给出布尔值[重复]

Can anyone help with this error? I would like to make log in session in my system. Here is the coding.

  <?PHP
   error_reporting (E_ALL^E_NOTICE);
   session_start();
   $username =$_POST['username'];
   $password =$_POST['password'];

    if ($username && $password)
     { // if 1

      $server='localhost';
       $userid2='root';
          $password2='';
          $dbname='suhaibah';

       $conn=mysql_connect("$server", "$userid2", "$password2");
       mysql_select_db("$dbname", $conn) or die(mysql_error()); 
         $query =  mysql_query("select * from staff where username = '$username'");

          $numrows = mysql_num_rows($query);

         if ($numrows !=0)
           { // if 2

     while ($row = mysql_fetch_assoc($query))
    { // if 3
    $dbusername = $row['username'];
    $dbpassword = $row['password'];
    } // if 3

      if ($username==$dbusername&&$password==$dbpassword)
       {
        //echo "You're in! <a href='index2.php'>click </a> here to enter";
        $_SESSION['username']=$username;
        header( 'Location: http://localhost/novel/lamanutamaadmin.php' ) ;
       }
       else 
          {echo " Incorrect Password!! <a href='/novel/landingpageadmin.php'>Click here to login</a>";}
   } // if 2    
else 
  die (" That user dosen't exist<a href='/novel/landingpageadmin.php'>Click here to login</a>");

 } // if 1
 else 
 {
  echo "Please enter userid and password!!<a href='/novel/landingpageadmin.php'>Click here to login</a>";
  }

?>


</body>
</html>
</div>
  • 写回答

1条回答 默认 最新

  • douye1940 2013-12-18 03:15
    关注

    The problem is not in mysql_num_rows, but in mysql_query!

    A call from mysql_query can return a resource on success or the boolean false on fail!

    http://php.net/mysql_query

    When mysql_num_rows invoked, it takes the boolean false (returned from mysql_query) as parameter, showing an indirect failure in mysql_query.

    Try to change it for

    $query =  mysql_query("select * from staff where username = '$username'") or die(mysql_error());
    

    and you'll surely get the right error.

    评论

报告相同问题?

悬赏问题

  • ¥15 想问一下树莓派接上显示屏后出现如图所示画面,是什么问题导致的
  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号