mercredi 23 septembre 2015

PHP/HTML - Web - Call things to appear

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.

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();




Aucun commentaire:

Enregistrer un commentaire