与数据库连接,但是什么也没发生

时间:2019-06-17 16:25:12

标签: php mysql

我刚刚在000webhost上上传了我的网站以与朋友进行测试,当我尝试注册/登录时它有问题,它可以将数据发送到mysql数据库,在表users中,它表明X是使用密码等登录的,但是在我的网站上,它没有显示应该在用户连接且登录表单未更改为注销表单时显示的内容。我不知道如何更好地描述它。在我的本地主机中,它运行良好!

我一直在搜索2天以获取答复,但仍然没有找到任何答案。 这是我登录时应该更改的index.php:

session_start();
    if(isset($_SESSION['userId'])){
        echo ' <nav>
        <ul class="nav-links">
        <li><a href="portfolio.php">Design Area</a></li>
        <li><a href="uploads/upload.php">Upload</a></li>
        <li><a href="contact.php">Contact</a></li>
    </ul>
    <div class="menu-phone">
        <div class="line"></div>
        <div class="line"></div>
        <div class="line"></div>
    </div>
    <form class="box" action="login/logout.php" method="post">
        <button class="btn-logout" type="submit" name="logout-submit">Logout</button>
    </form>
    <p class="info-log-in">Connected</p>
    </nav>';
    } else {
        echo '
        <nav>
        <form class="box" action="login/login.inc.php" method="post">
        <input type="text" name="mailuid" placeholder="Username/E-mail..." class="text-login">
        <input type="password" name="pwd" placeholder="Password..." class="text-login">
        <button class="btn-login" type="submit" name="login-submit">Login</button> 
        <a class="btn-signup" href="signup.php">Signup</a><p class="or">OR</p></nav>
        </form>
        <p class="info-log">Disconnected!</p>
        ';
    } 

和login.inc.php

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

    require 'dbh.inc.php';

    $mailuid = $_POST['mailuid'];
    $password = $_POST['pwd'];

    if(empty($mailuid) || empty($password )){
        header("Location: ../index.php?error=emptyfields");
        exit();
    }
    else {
        $sql = "SELECT * FROM users WHERE widUsers=? OR emailUsers=?;";
        $stmt = mysqli_stmt_init($conn);
        if(!mysqli_stmt_prepare($stmt, $sql)){
            header("Location: ../index.php?error=sqlerror");
            exit(); 
        }
        else {
            mysqli_stmt_bind_param($stmt, "ss", $mailuid, $mailuid);
            mysqli_stmt_execute($stmt);
            $result = mysqli_stmt_get_result($stmt);
            if($row = mysqli_fetch_assoc($result)){
                $pwdCheck = password_verify($password, $row['pwdUsers']);
                if($pwdCheck == false){
                    header("Location: ../index.php?error=wrongpassword");
                    exit();
                }
                else if($pwdCheck == true){
                    session_start();
                    $_SESSION['userId'] = $row['idUsers'];
                    $_SESSION['userUId'] = $row['widUsers'];

                    header("Location: ../index.php");
                    exit();
                }
                else {
                    header("Location: ../index.php?error=wrongpassword");
                    exit();
                }
            }
            else {
                header("Location: ../index.php?error=nouser");
                exit();
            }
        }
    }
}
else {
    header("Location: ../index.php");
    exit();
}

0 个答案:

没有答案