'submit button just refreshes php
<form method="POST">
<div class="form-outline form-white mb-4">
<input type="password" name="password" class="form-control" required/>
<label class="form-label" for="form">Pass</label>
</div>
<button type="Submit" value="send" class="btn transparent btn-block" style="color: white;">Submit</button>
</form>
if (isset($_POST['submit'])) {
$password=$_POST['password'];
if ($password=='password') {
header("location:ari.html");
exit();
}
else
echo "Incorrect.";
}
I'm beginning php currently and I'm trying to use a login method, but whenever I press my submit button my code refreshes and doesn't move onto the next page I indicated. (location:ari.html) If I could get help on what I did wrong that would be great thanks.
Solution 1:[1]
you should consider using action attribute in form tag and point into some POST url that retrieve your data use action line this
<form method="POST" action="/ari.php">
submit button refresh the page without action attribute it just point to current URL if you dont fill it
Solution 2:[2]
Take a look at this line:
<form method="POST">
What happening is that when you are submitting the form it is sending data to the same page.
In this line:
if (isset($_POST['submit']))
I found no tag with name='submit' attribute. You should put this in your submit button.
If you want to send it to another page then use the action attribute in form tag and point your data to that page like action=yourpage.php
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mrdeveloper |
| Solution 2 | Sohan Arafat |
