dpfw3607 2016-11-25 17:32
浏览 16

我的登录页面将转到下一页,但首先显示警告标志

 <?php

     session_start();

            $c=mysqli_connect('mysql.hostinger.in','u808297599_eval','nandini123');
      if(!$c)
      exit("ERROR");
   $db=mysqli_select_db($c,'u808297599_eval');
   if(!$db)
    exit("ERROR");
       $e=$_POST['username'];
       $p=$_POST['password'];
        $_SESSION['username']=$e;
        $query="SELECT * FROM tecaherlogin WHERE username='$username' AND     password='$password' ";
            $result=mysqli_query($c,$query);
       $exists=mysql_num_rows($result);

       if ($exists!=0)
       {
                     //while loop
              while ($row = mysqli_fetch_assoc($query))
              {
               $dbusername = $row['username'];
               $dbpassword = $row['password'];
                  }
              if($dbpassword==$p)
                        {
                Print '<script>alert("Correct Password!");</script>';
                 Print '<script>window.location.assign("evaluate.html");     </script>';}

                else
             {
                Print '<script>alert("Incorrect Password!");</script>';
                 Print       '<script>window.location.assign("teacherloginnew.html");</script>';
    }
   }
  else
  echo "user does not exist!";
  ?>

I get this error:

warning:mysqli-fetch-assoc expects parameter 1 to be mysqli_result, string given

This shows up before loading the page, the warning sign should not be there as this is for my project. Please help.

  • 写回答

1条回答 默认 最新

  • dongruolin5324 2016-11-25 17:35
    关注

    You're trying to fetch_assoc of a string $query.

    Your mysqli_result is the variable $result, which is the one you should be passing here:

    while ($row = mysqli_fetch_assoc($query))
    

    Do this:

    while ($row = mysqli_fetch_assoc($result))
    

    This query below will already verify if the password is correct. So you don't need to fetch assoc again below.

    $query="SELECT * FROM tecaherlogin WHERE username='$username' AND     password='$password' ";
    

    You just need this:

    $exists=mysql_num_rows($result);
    
        if ($exists!=0)
        {
            Print '<script>alert("Correct Password!");</script>';
            Print '<script>window.location.assign("evaluate.html");     </script>';
        }
        else
        {
            Print '<script>alert("Incorrect User or Password!");</script>';
            Print '<script>window.location.assign("teacherloginnew.html");</script>';
        }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题