Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <style>
- table {border-collapse: collapse; }
- table, td {border: 1px solid black; }
- </style>
- </head>
- <body>
- <?php
- //Get names of database to establish connection
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "opslag";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- mysqli_set_charset($conn,"utf8");
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- ?>
- <!-- Make two input fields to get username and password. POST is used to save the data that the user has entered. the form has an id so I can change
- its attributes later if needed -->
- Login
- <form id="myForm" method="POST">
- username: <input type="text" name="username" > <br>
- password: <input type="text" name="password" > <br>
- <!-- submit button is created and given and id so I can refer to it elsehwere -->
- <input id=login type="submit" value=Submit>
- </form>
- <?php
- //check if text has been entered in username and password input-fields and then check if the given username and password is in the database-table "bruger"
- if(isset($_POST["username"])){
- if (!empty($_POST["username"] && !empty($_POST["password"]))){
- $username=$_POST["username"];
- $password=$_POST["password"];
- $myData="SELECT * from bruger where username='$username' and password='$password';";
- $myResult=$conn->query($myData);
- //If the username and password is in the database...
- if ($myResult->num_rows>0){
- ?>
- <script>
- // The JavaScript is used to change "myForm" action to "opslagsTavle.php" and then click the sumbit button so the action is activated
- document.getElementById("myForm").action = "opslagsTavle.php";
- document.getElementById("login").click();
- </script>
- <?php
- }else{
- echo "The entered username or passwor does not exist";
- }
- }
- }
- $conn->close();
Add Comment
Please, Sign In to add comment