My PHP authentication page isn't retrieving the data correctly from the DB, when correct credentials are entered the incorrect echo keeps appearing. Please can someone shed some light on where I'm going wrong? Many thanks.
EDIT: Sorry I forgot to mention that it's supposed to be vulnerable to injection as I wish to use it for a demonstration.
HTML:
<form method="POST" action="connection.php">
User <br><input type="text" name = "user" size="40"><br>
Password <br><input type ="password" name="pass" size="40"><br>
<input id="button" type="submit" name="submit" value="Log-In">
PHP:
<?php
// Grab User submitted information
$user = $_POST["user"];
$pass = $_POST["pass"];
// Connect to the database
$con = mysqli_connect("localhost","my_user","my_pass");
// Make sure we connected successfully
if(! $con)
{
die('Connection Failed'.mysqli_error());
}
// Select the database to use
mysqli_select_db(login, $con);
$result = mysqli_query("SELECT usernames, password FROM accounts WHERE usernames = $user");
$row = mysqli_fetch_array($result);
if($row[usernames]==$user && $row[password]==$pass)
echo"You are a validated user.";
else
echo"Sorry, your credentials are not valid, Please try again.";
?>
DB Details:
database name: login
table name: accounts
rows:
usernames
password