具有用户块功能的PHP多IF条件

时间:2018-06-11 04:18:43

标签: php

我想用php创建一个登录脚本,我添加了各种条件,但是当我运行它时会出错。

我想制作"电子邮件验证" - 作为主要的" LogCount"然后"状态"然后一切都是=" 1"然后显示 dashboard.php

<?php
$msg = "";

if (isset($_POST['submit'])) {
    include("config.php");
    //$con = new mysqli('localhost', 'research_emailC', 'test123', 'research_phpEmailConfirmation');

    $username = $con->real_escape_string($_POST['username']);
    $password = $con->real_escape_string($_POST['password']);

    if ($username == "" || $password == "")
        $msg = "Please check your inputs!";
    else {
        $sql = $con->query("SELECT ID, password, isEmailConfirmed, Status FROM users WHERE username='$username'");
        if ($sql->num_rows > 0) {
            $data = $sql->fetch_array();
            //if (password_verify($password, $data['password'])) {
                if ($data['isEmailConfirmed'] == 0)
                    $msg = "Please verify your email!";
                else {
                    $msg = "You have been logged in";
                }
            }else
                $msg = "Please check your identity";
        }

        if ($data['Status'] == 0)
            $msg = "Your account is suspended!";
        else{
            $msg = "Something went wrong!";
        } 

        if ($data['LogCount'] == 0)
            msg=" you are new user ";
        else{
            $msg = "Something wrong here!";
        } 

    }
}
?>

1 个答案:

答案 0 :(得分:0)

尝试以下方法:

<?php
$msg = "";

if (isset($_POST['submit'])) {
    include("config.php");
    //$con = new mysqli('localhost', 'research_emailC', 'test123', 'research_phpEmailConfirmation');

    $username = $con->real_escape_string($_POST['username']);
    $password = $con->real_escape_string($_POST['password']);

    $suc = 1;


    if ($username == "" || $password == "")
        $msg = "Please check your inputs!";
        $suc = 0;
    else{
        $sql = $con->query("SELECT ID, password, isEmailConfirmed, Status FROM users WHERE username='$username' and password='$password'");
        //LogCount field is not taken here

        if ($sql->num_rows > 0) {
            $data = $sql->fetch_array();
            if ($data['isEmailConfirmed'] == 0){
                $msg = "Please verify your email!";
                $suc = 0;
            }
            if ($data['Status'] == 0){
                $msg = "Your account is suspended!";
                $suc = 0;
            }
        }else{
            $msg = "Please check your username/password";
            $suc = 0;
        }
    }

    if ($suc == 1){
        //if take the LogCount field please check the following
        if ($data['LogCount'] == 0){
            msg = " you are new user ";//Welcome to our site
        }else{
            //Increase the LogCount Here
            msg = " You have been logged in";
        }               
        //Otherwise
        msg = " You have been logged in";
        //Set session value 
        //Re-direct to dashboard Page
    }else{
        //Same Login Page
    }
}
?>