Home > OS >  submit button just refreshes php
submit button just refreshes php

Time:02-07

<form method="POST">
    <div >
  <input type="password" name="password"  required/>
  <label  for="form">Pass</label>
</div>
    <button type="Submit" value="send"  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.

CodePudding user response:

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

CodePudding user response:

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

CodePudding user response:

<form method="POST" action="bk_enroll.php">
    <div >
  <input type="password" name="password"  required/>
  <label  for="form">Pass</label>
</div>
    <button type="Submit" name="submit" value="send"  style="color: white;">Submit</button>
  </form>
<?php
   if (isset($_POST['submit'])) {
    echo $password=$_POST['password']=='password'?header("location:ari.html"):"Incorrect.";
}
?>

have updated this code and working fine for me...hope u got the answer

  •  Tags:  
  • Related