I'm new to PHP programming and have a simple program where I have an index page which accepts username and password. If user doesn't exist or wrong credentials are provided then I want to show index page again with error message. Here is what I have so far on my index.html:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="Bella" >
<title>Company Name - Log In</title>
<!-- Bootstrap Core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- Custom CSS -->
<link href="css/custom.css" rel="stylesheet">
<!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/libs/html5shiv/3.7.0/html5shiv.js"></script>
<script src="https://oss.maxcdn.com/libs/respond.js/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div id="fullscreen_bg" class="fullscreen_bg"/>
<div class="container">
<form class="form-signin" action="loginAction.php" method="post">
<h1 class="form-signin-heading text-muted">Log In</h1>
<input type="text" name="email" class="form-control" placeholder="Email address" required="" autofocus="">
<input type="password" name="password" class="form-control" placeholder="Password" required="">
<button class="btn btn-lg btn-primary btn-block" type="submit">
Log In
</button>
<a href="register.html" class="btn btn-md btn-warning btn-block">Register</a>
</form>
</div>
<!-- /.container -->
<!-- jQuery -->
<script src="js/jquery.js"></script>
<!-- Bootstrap Core JavaScript -->
<script src="js/bootstrap.min.js"></script>
<!-- Script to Activate the Carousel -->
<script>
$('.carousel').carousel({
interval: 5000 //changes the speed
})
</script>
</body>
</html>
My LoginAction.php is:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
//Set the Post results to variables
$email = $_POST("email");
$password = md5($_POST("password"));
//Get the database username, passwords, etc.
include('config.php');
// Create connection with the server
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
//Check for user
$sql = "SELECT * FROM users WHERE email=" . $email . " AND password=" . $password . "";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
mysqli_close($conn);
session_start();
$_SESSION['email'] = $row['email'];
$_SESSION['id'] = $row['id'];
$_SESSION['admin'] = true; //user is authenticated and the user is admin
header"portal.php"; //redirect to another page
}
}
else {
mysqli_close($conn);
echo "<div class='alert alert-warning'>No User Found</div>";
//header("Location: http://example.com/myOtherPage.php");
//header"portal.php"; //redirect to another page
include"index.html";
}
?>
It currently shows me blank LoginAction.php