PHP mySQL check if username and password are in the database

前端 未结 4 437
死守一世寂寞
死守一世寂寞 2020-12-10 23:49

I want my code to check if the username and password exist in my database. It does work hardcoded, but I want to do it with a database.Right now this is what I have:

4条回答
  •  猫巷女王i
    2020-12-11 00:08

     error_reporting(E_ALL);  
    ini_set('display_errors', 1);
    session_start();
    if(count($_POST)>0) 
    {
        include'includePhp.php';
        $sql="SELECT * FROM admin WHERE username='" . $_POST['username'] . "' AND password = '". $_POST['password']."'";
        $result = $con->query($sql);
    if ($result->num_rows > 0) 
        {
      while($row = $result->fetch_assoc()) 
                {
            if(!empty($row) && !empty($row['username']) AND !empty($row['password']))
                {
                    $_SESSION['username'] = $row['username'];
                    echo "SUCCESSFULLY LOGIN ";
                    header("Location: inDhanush.php");
                }
            else 
            {
            echo "Try again";
            }
        }
    }
    

    }

提交回复
热议问题