$query="select * from yonghu_t where yonghu_yhmc='$username'";$result=mysql_query($query);$result_u=mysql_fetch_row($result);

echo $query;

echo mysql_num_rows($result);mysql_num_rows($result)返回的总是0,数据库有或者没有返回的都是0 为什么啊 ?

解决方案 »

  1.   

    把echo $query;语句输出后的内容到mysql数据库中去运行看有没有值?
      

  2.   

    肯定有撒!我就做个登陆代码 全部给你看,看错误出现在哪
    <?php
    include '../db/conn.php';
    $username=$_REQUEST['username'];
    $password=$_REQUEST['password'];$query="select * from yonghu_t where yonghu_yhmc='$username'";$result=mysql_query($query);
    $rows=mysql_num_rows($result);
    //$result_u=mysql_fetch_row($result);
    if($rows){
    if($password==$result_u[1]){
    session_start();
    $_SESSION['username']=$username;
    echo "<script>";
    echo "window.location.href='../main.html'";
    echo "</script>"; }else{
    echo "<script>";
    echo "alert('密码或者账号错误');";
    echo "window.location.href='../index.php'";
    echo "</script>";
    }
    }
    else{
    echo "<script>";
    echo "alert('用户名不存在');";
    echo "window.location.href='../index.php'";
    echo "</script>";
    }?>
      

  3.   

    $result_u注释掉干嘛?后面没法比较啊!
      

  4.   


    $query="select * from yonghu_t where yonghu_yhmc='$username'"; $result=mysql_query($query); $result_u=mysql_fetch_row($result); 
    print_r($result_u);  //打印出来看一下
    //echo $query; //echo mysql_num_rows($result); 
      

  5.   

    你看看输出的源文件里面的username是乱码不
      

  6.   


    确定一下SQL语句是否有问题 
      

  7.   

    把$query打印出来,到mysql执行。没问题啊 能够查询到
      

  8.   

    $query="select * from YONGHU_T where YONGHU_YHMC='admin'";$result=mysql_query($query);
    $result_u=mysql_fetch_row($result);
    echo $result_u[0];
    就这句代码 
    $result_u[0]什么都没有;
      

  9.   

    哎呀,我的错,我的错!数据库连接错了!掉了s ,不好意思!pub 应该是pubs