I have no idea why this is allowing free entry for any password and username combination, I've tried all I possibly could but to no avail. The slightest help would be appreciated. The php here should output directly into the form below it.
<?php
if (isset($_POST['name'])) {
$username = $_POST['name'];
$apassword = $_POST['password'];
$host = "127.0.0.1";
$user = "root";
$password = "";
$database = "test_site";
$table = "admin";
$link = mysqli_connect($host, $user, $password, $database);
if (!$link) {
echo "Error: Unable to connect to MySQL.";
exit;
}
$query = "SELECT first_name, last_name, password FROM $table WHERE username='$username' AND password='$apassword'";
$result = mysqli_query($link, $query);
if (mysqli_num_rows($result)==1) {
$row = mysqli_fetch_assoc($result);
$first_name = $row['first_name'];
$last_name = $row['last_name'];
}
mysqli_close($link);
echo "Hello, " . $_POST['name'] . ".";
} else {
$error = "Your Login Name or Password is invalid";
?>
<form name="login" method="POST" action="index.php">
<table align="center">
<tr>
<td><font size="2">Username:</font></td>
<td><input size="11" type="username" name="name" placeholder="Username" required></td>
</tr>
<tr>
<td><font size="2">Password:</font></td>
<td><input size="11" type="password" name="password" placeholder="Password" required></td>
</tr>
<tr>
<td><input type="submit" value="Login"></td>
</tr>
</table>
</form>
<?php
}
?>