I'm making a login page for my website which connects to a mysql database that stores the login details. However when I submit the form it redirects the information regardless of whether or not the login is valid. I'm very confused as to what could be wrong.
My form:
<form name="login" action="edit_profile/index.php" method="post"> //redirects to this page regardless of what has been submitted
<fieldset>
<legend>Please enter your login details</legend>
<label for="username">Username</label>
<input id="username" name="username" type="text" value="" required/><br>
<label for="password">Password</label>
<input id="password" name="password" type="password" value="" required/><br>
<input type="submit" value="submit"/>
</fieldset>
The pHp script:
<?php require_once "connectdb.php";?>
<?php
if(isset($_POST["submit"])){
$username=$_POST["username"];
$password=$_POST["password"];
$query=mysql_query("SELECT * FROM login_details WHERE Username='".$username."'AND Password='".$password."'");
$numrows=mysql_num_rows($query);
if($numrows!=0) {
while($$row=mysql_fetch_asoc($query)) {
$dbusername=$row["Username"];
$dbpassword=$row["Password"];
}
if($user == $dbusername && $pass == $dbpassword) {
session_start();
$_SESSION["user_session"]=$user;
echo "<pre>";
print_r($_SESSION);
echo '</pre>';
}
} else {
echo "Invalid username or password!"; //does not echo
}
}
?>