Not all the code, no, I only put in the bits that matter related to the issue, however if it's needed:
index.html (The login page)
HTML:
<!DOCTYPE html>
<html style="background-color: #444444">
<head>
<meta charset="UTF-8">
<title>Log-in</title>
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
<link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<link href="//code.ionicframework.com/ionicons/1.5.2/css/ionicons.min.css" rel="stylesheet" type="text/css" />
<link href="css/AdminLTE.css" rel="stylesheet" type="text/css" />
</head>
<body style="background-color: #444444">
<div class="col-md-6" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);">
<div class="col-md-6" style="position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);">
<center>
<div class="box box-warning">
<center>
<div class="box-header">
<h1>Log-in</h1>
</div>
<div class="box-body">
<form role="form" method="post" action="checklogin.php">
<div class="form-group">
<input class="form-control" type="text" name="username" placeholder="Username">
</div>
<div class="form-group">
<input class="form-control" type="password" name="pass" placeholder="Password">
</div>
<div class="form-group">
<input style="width: 100%" type="submit" name="login" class="btn btn-primary" value="Log in">
</div>
</form>
<form role="form" method="post" action="apply.html">
<div class="form-group">
<input style="width: 100%" name="apply" type="submit" class="btn btn-primary" value="Apply for an account">
</div>
</form>
<?php
if($count == 0) {
echo "Wrong username or password.";
}
?>
</div>
</center>
</div>
<!-- <div id="error"><img src="https://dl.dropboxusercontent.com/u/23299152/Delete-icon.png" /> Your caps-lock is on.</div> -->
</center>
</div>
</div>
<script src='[url]http://codepen.io/assets/libs/fullpage/jquery_and_jqueryui.js'[/url]></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js" type="text/javascript"></script>
<script src="../../js/AdminLTE/app.js" type="text/javascript"></script>
<script src="../../js/AdminLTE/demo.js" type="text/javascript"></script>
</body>
</html>
checklogin.php (Bit that checks if the details are valid)
PHP:
<?php
ob_start();
$host="localhost"; // Host name
$username="serverpanel"; // Mysql username
$password="ServerPanel123"; // Mysql password
$db_name="serverpanel"; // Database name
$tbl_name="users"; // Table name
// Connect to server and select databse.
$con = mysqli_connect("$host", "$username", "$password", "$db_name")or die("cannot connect");
// username and password sent from form
$user=$_POST['username'];
$pass=$_POST['pass'];
// To protect MySQL injection (more detail about MySQL injection)
$user = stripslashes($user);
$pass = stripslashes($pass);
$user = mysqli_real_escape_string($con, $user);
$pass = mysqli_real_escape_string($con, $pass);
$sql="SELECT * FROM $tbl_name WHERE user_name='$user' and user_pass='$pass'";
$result=mysqli_query($con, $sql);
// Mysql_num_row is counting table row
$count=mysqli_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
$_SESSION['user'] = $user;
$_SESSION['pass'] = $pass;
header("location:login_success.php");
}
else {
header("location:index.html");
}
ob_end_flush();
login_success.php (Once the login is successful)
PHP:
<?php
session_start();
if(!isset($_SESSION['user'])){
header("location:dashboard.html");
}
?>
Note: I changed the $email var and 'email' in the form to $user and 'username' since posting this thread (Which is why the code I just posted is slightly different in that way).
Side question: I'm also trying to get it so that on the page that login_success.php redirects to it displays the username the person logged in with. I used the following code to try and achieve it:
However this just prints nothing. It makes me assume that the variable $user isn't being passed through, why might this be happening and what may I do to fix it?
Thanks in advance - I'd really appreciate help with both of these if anyone has the time and knowledge.