I have a basic form, I only want it execute when the users input matches a set one. How can I make it so the user can only get to the add books page if the supply the "Admin" username and the password "password1"?
//Admin Login
echo "<form method='post' action='addBooks.php'>
Username:<br>
<input type='text' name='Username' value='Admin'>
<br>
Password:<br>
<input type='text' name='password' value=''>
<br><br>
<input type='submit' name='sbmt' id='sbmt' value='user_value' class='user_class' onSubmit='return submit();'/>
</form>";
function submit(){
if($_POST['Username'] == 'Admin')&&($_POST['password'] == 'Password1'){
return true;
}
else{
alert("Please check Username and Password")
return false;
}
}
Edit:
To clear up the issue.
I am trying to have a form with a username and password input. When the user clicks submit on this form it currently takes the user to addbooks.php. I want to make this conditional so that the user can only access the addbooks.php page if the username they provide ="Admin" and the password the provide = "Password1". I am currently trying to execute the submit function on the button click and the submit function is supposed to check if username and password match admin and password1. if they do it should let you through to addbooks.php