dongzhukuai8177 2015-09-23 20:20
浏览 43
已采纳

PHP / HTML - Web - 调用要显示的内容[关闭]

What i want to do is make things appear.

I have created a login system. What i want to do is make a box saying "incorrect password" or something like that when they incorrectly answer the username and password.

The backend is fairly simple. I plan to make it more complex after i get the answer to this. Also, some of the front end is written in Bootstrap. And, i am using MySQL to contain the Username and Password information.

What i need is, a simple PHP variable to be called later in the HTML. I will not be combining the backend and the frontend together.

My Code:

Frontend:

<html>
    <head>
        <link rel="stylesheet" href="../../css/bootstrap.min.css"/>

        <title>User Login</title>
    </head>

    <body>
        <div class="container">
            <div align="center" class="jumbotron">
                <div class="container">
                    <h1>User Login</h1>
                </div>
            </div>

            <div align="center" class="container">
                <form action="login.php" method="post">
                    <div class="form-group">
                        <input type="text" name="username" id="username" placeholder="Username"/>
                    </div>

                    <div class="form-group">
                        <input type="password" name="password" id="password" placeholder="Password"/>
                    </div>

                    <input value="Submit" type="submit" class="btn btn-primary"/>
                </form>
            </div>
        </div>
    </body>
</html>

Backend:

<?php

    session_start();

    $servername = "**BLOCKED**";
    $username = "**BLOCKED**";
    $password = "**BLOCKED**";
    $dbname = "**BLOCKED**";

    $conn = new mysqli($servername, $username, $password, $dbname);

    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    $sql = "SELECT password FROM user WHERE username = '" . $_POST["username"] . "'";
    $result = $conn->query($sql);

    if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc())
        {
            if ($row["password"] == $_POST["password"])
            {
                $_SESSION["Authenticated"] = true;

                header("Location: ../");
            }else
            {
                echo "Login failed";
            }

            //Debug

            //echo " password DB: " . $row["password"];
            //echo " password IN: " . $_POST["password"];
        }
    } else {
        echo "User not found!";
    }

    $conn->close();
  • 写回答

3条回答 默认 最新

  • doujin8476 2015-09-23 20:45
    关注

    add/replace:

    $result = $conn->query($sql);
    $FORM_DATA = ''; // variable with will go to the view (html)
    

    &

    //echo "Login failed";
    $FORM_DATA = 'Wrong login or password';
    

    &

    //echo "User not found!";
    $FORM_DATA = 'Wrong login or password';
    

    & View (html) after:

    <div align="center" class="jumbotron">
    <div class="container">
    <h1>User Login</h1>
    </div>
    </div>
    

    add html with variable

    <?php if($FORM_DATA): ?>
    
    <div align="center" class="jumbotron">
    <div class="container">
    <p style="color: red"><?php echo $FORM_DATA ?></p>
    </div>
    </div>
    
    <?php endif; ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 怎样才能让鼠标沿着线条的中心线轨迹移动
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?
  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?