Hey Guys,
I am creating a login application using PHP/Phpmyadmin and I am having an issue. I found another program online and I am mimicking its function, but I am unable to get it to work. Basically I have a database named ‘vendors’ with a table called ‘users’. I want the login app to pull the username and password from my database and approve/reject depending on if the user is found. I have been working on this for some time and have not been able to figure it out. Any help is much appreciated.
<?php session_start(); ?>
<?php include('dbcon.php'); ?>
<html>
<head>
<title>LOGIN PAGE</title>
<link rel="stylesheet" type="text/css" href="style2.css">
<link rel="shortcut icon" href="img/favicon.ico" type="image/x-icon">
</head>
<body>
<div class="form-wrapper">
<form action="#" method="post" autocomplete="off">
<h3>Login here</h3>
<div class="form-item">
<input type="text" name="username" required="required" placeholder="Username" autofocus required></input>
</div>
<div class="form-item">
<input type="password" name="password" required="required" placeholder="Password" required></input>
</div>
<div class="button-panel">
<input type="submit" class="button" title="Log In" name="login" value="Login"></input>
</div>
</form>
<?php
if (isset($_POST['login']))
{
$username = mysqli_real_escape_string($con, $_POST['user']);
$password = mysqli_real_escape_string($con, $_POST['pass']);
$query = mysqli_query($con, "SELECT * FROM users WHERE password ='$password' and username ='$username'");
$row = mysqli_fetch_array($query);
$num_row = mysqli_num_rows($query);
if ($num_row > 0)
{
$_SESSION['id']=$row['id'];
header('location:home.php');
}
else
{
echo 'Invalid Username and Password Combination';
}
}
?>
<div class="reminder"><br><br>
<p>Not a vendor? <a href="register.php">Register Here</a></p>
</div>
</div>
</body>
</html>