Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/228.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Php登录仅在mysqli_num_rows等于零时工作,否则不会';不行,我卡住了_Javascript_Php_Html - Fatal编程技术网

Javascript Php登录仅在mysqli_num_rows等于零时工作,否则不会';不行,我卡住了

Javascript Php登录仅在mysqli_num_rows等于零时工作,否则不会';不行,我卡住了,javascript,php,html,Javascript,Php,Html,如果mysqli_num_rows==false,那么代码可以工作,但为什么num rows不工作,我无法获得它,我尝试了所有方法,但出现了相同的错误 <?php //Start session session_start(); //Include database connection details require_once('db.php'); if(isset($_POST['submit'])){ $username=$_POST['usernam

如果mysqli_num_rows==false,那么代码可以工作,但为什么num rows不工作,我无法获得它,我尝试了所有方法,但出现了相同的错误

 <?php
 //Start session
 session_start();

//Include database connection details
require_once('db.php');
    if(isset($_POST['submit'])){
        $username=$_POST['username'];
        $password=$_POST['password'];
        $query="SELECT * FROM users WHERE username='$username' and password='$password'";
        $result=mysqli_query($con,$query);
        if($row=mysqli_num_rows($result)==1){
            mysqli_fetch_array($con,$result);
            echo 'Logged in';
            header('location:profile.php');
        }
        else{
            echo 'error occured';
        }
    }
?>
<form method="POST">
 <input type="text" name="username" placeholder="username">
<input type="text" name="password" placeholder="password">
<input type="submit" name="submit">

</form>



把代码放在这里。不是图片对不起,兄弟,我只是在下面贴了一些密码,密码不正确,每次我试图写用户名和密码,我确定我写的用户名和密码是正确的,甚至在数据库中检查了两次。你对密码使用了加密吗?以md5为例?$password=md5($password)@GiorgiMacharashvili现在就检查我编辑的代码。使用它吧,非常感谢!!!从昨天起,我就对这件事感到困惑,非常感谢兄弟。
<form method="POST">
 <input type="text" name="username" placeholder="username">
<input type="text" name="password" placeholder="password">
<input type="submit" name="submit">
</form>
<?php
error_reporting(E_ALL); // check all type of error
ini_set('display_errors',1); // display those errors
session_start();
require_once('db.php');
if(!empty(trim($_POST['username'])) && !empty(trim($_POST['password']))){ // check with posetd value
   $user_name = trim($_POST['username']);
   $password = md5(trim($_POST['password']));
   $query = "SELECT * FROM users where username='$username' and password = '$password'"; // don't use plain password, use password hashing mechanism
   $result = mysqli_query($con,$query); // run the query
   if(mysqli_num_rows($result)>0){ // if data comes
        // here do some data assignment into session
        header('location:profile.php'); // go to other page
   }else{
       echo "Login creadentials are not correct"; // else no user is there with the given credentials
   }
}else{
  echo "please fill the form value";
}
?>