I'm trying my best to make a simple login system just as something to do in my time, as someone extremely new to PHP and MySQL I am still very confused, after hours of tutorials and things that should supposedly help I am still have a lot of difficulty.
You can find the test at beastfox.com/index.php (the index.html is just a dummy for now for the final design)
Username: Username Password: Password (First letter Capital)
I know you are all probably really advanced but I am still just trying to learn something new,
I'll put my PHP Code in here and I hope you can try and see if I have done something wrong? I'll try and explain what happens, when you enter the Username and Password it is meant to direct to a test page (myaccount.php) and it should keep a session. but it still fails to do so, My guess is that I have an error in either MySQL or something else, Here is my database also, I wasn't sure if I should cover my details and the name of MySQL account. But I have anyway just in case, If needs be i can provide you with it!

I wasnt exactly sure how to do a MySQL Fiddle or a PHP Fiddle, so I'm just going to paste the code. This is all one .php file and it has html code intergrated into it.
<?php
include("database.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST") {
$username = mysqli_real_escape_string($db,$_POST['username']);
$password = mysqli_real_escape_string($db,$_POST['password']);
$sql = "SELECT id FROM admin WHERE username = '$username' and passcode = '$password'";
$result = mysqli_query($db,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$active = $row['active'];
$count = mysqli_num_rows($result);
if($count == 1) {
session_register("username");
$_SESSION['login_user'] = $username;
header("location: myaccount.php");
}else {
$error = "Your Login Name or Password is invalid";
}
}
?>
And the HTML, Which is in the SAME document
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<link rel="apple-touch-icon" sizes="57x57" href="favicon/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="favicon/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="favicon/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="favicon/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="favicon/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="favicon/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="favicon/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="favicon/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="favicon/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="favicon/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="favicon/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="favicon/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="favicon/favicon-16x16.png">
<link rel="manifest" href="favicon/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="favicon/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<meta charset="UTF-8">
<link rel="stylesheet" type="text/css" href="main.css">
<link href="https://fonts.googleapis.com/css?family=Raleway:100" rel="stylesheet">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300" rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto+Condensed" rel="stylesheet">
</head>
<body>
<div class="LoginBox" style="">
<div class="element_wrapper">
<a class="Login">Login</a>
<class>
<center>
<form action = "" method = "post">
<input type = "text" name = "username" class = "username" value="Username"/><br /><br />
<input type = "password" name = "password" class = "password" value="Password" /><br/><br />
<input type = "submit" value = " Submit " class="btn"/><br />
</form></center>
</class>
</div>
</div>
</body>
</html>
I hope i didn't make anything too complex, and I'm sorry that Markdown couldn't seem to understand my code, If any indentation or something seems wrong it shouldn't be. But I have got everything sorted out for the files I needed, Eg (database.php to connect to mySQL and session.php and the myaccount.php)
<?php
session_start();
$server="beastfox.com";
$user="-";
$password="-";
$database= "-_database";
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
?>