{==HTML CODE HERE==}
<!DOCTYPE html><html>
<head>
<!--Import Google Icon Font-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<!--Import materialize.css-->
<link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/>
<!-- online cdn -->
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css">
<!-- Compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script>
<!--Let browser know website is optimized for mobile-->
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
</head>
<body>
<div class="center">
<h3 class="teal-text" style="font-weight: bold;">Login System</h3>
</div>
<form action="hello.php" method="POST">
<div class="container">
<div class="row">
<div class="input-field col s12">
<input id="email" type="email" name="username" class="validate">
<label for="email">Enter Your Username</label>
</div>
</div>
<div class="row">
<div class="input-field col s12">
<input id="password" type="password" name="password" class="validate">
<label for="password"> Enter Your Password</label>
</div>
</div>
<div class="center">
<button class="btn waves-effect waves-light" type="submit" name="submit">Login
<i class="material-icons right">send</i>
</button>
</div>
</div>
</form>
<!--JavaScript at end of body for optimized loading-->
<script type="text/javascript" src="js/materialize.min.js"></script>
</body>
</html>
{==PHP CODE HERE==}
<?php
$dbservername ="localhost";
$dbusername ="root";
$dbpassword ="";
$dbname ="test_db";
$con = mysqli_connect($dbservername,$dbusername,$dbpassword,$dbname);
if ($con)
{
if (isset($_POST['submit'])) {
# code...
$user=$_POST['username'];
$pass=$_POST['password'];
$sql="select * from demo";
$res=mysqli_query($con,$sql);
if(mysqli_num_rows($res)){
$x=mysqli_fetch_assoc($res);
// echo $x['password'];
// echo "<br>";
// echo $x['username'];
if ($x['password']===$pass) {
# code...
echo "You Have Successfully Logged in";
}
else{
header("Location:index.php");
}
}
else{
header("Location:index.php");
}
}
}
?>
Comments