Simple login returning blank page

前端 未结 4 901
闹比i
闹比i 2021-01-29 10:47

I\'m learning PHP and I have made a simple login script but the problem is that it only redirects me to a blank page. It\'s meant to redirect to index.php if user credentials ar

4条回答
  •  一向
    一向 (楼主)
    2021-01-29 11:46

    First of all the name of your submit button is "submit". And you are checking if the "login" is post or not.

    if(isset($_POST['login']))
    {
    

    it should have been:

    if(isset($_POST['submit']))
    {
    

    You have written :

    if($user || $password != NULL)
    {
    

    it should have been:

    if($user != NULL || $password != NULL)
    {
    

    You have used mysqli and mysql command which is not a good practice

    $result=mysqli_query($sql);
    
        $row=mysql_fetch_array($result);
    

    Instead of

    if($row['user'] == $user && $row['password'] == $password)
        {
    //this code again check for condition which is already checked in the sql statement
    

    it is better practice to write :

    if($row->num_rows==1)
        {
    

    in index.php you have written

    if(!isset($_SESSION["loggedIn"])){
    

    it should have been

    if(!isset($_SESSION["loggedin"])){
    

    since you have stored the lowercase index while storing into session.

提交回复
热议问题