user3883259
user3883259

Reputation: 25

HTML Form Submit not readable for PHP

i´ve got a little problem with my php code. The code contains a form that reloads the document. But after the reaload I cant read the POST data. Here is the HTML code:

<form action="config_page.php" method="post">
  ... some Inputs
  <input type="submit" value="Save" name="config_btn" class="submitbtn_2">
</form>

On top of config_page.php ive got this PHP code:

if(isset($_POST["config_btn"])){
  echo "isset";
  //Some Database writing
}else{
  echo "is not set";
}

Bizarrely, the output "is not set" always appears after submiting the form, but Database Changes are applied anyway... (Database Changes are only performed if the isset statement is true)

Can someone figure out the problem?

Thanks for your help!

Upvotes: 0

Views: 126

Answers (1)

Rakesh Sharma
Rakesh Sharma

Reputation: 13738

POST values will always set after post or submit form with form post method

echo "is not set"; always true until you not click on submit or post any values. after submit click you will find $_POST["config_btn"] is set true so db queries runs.

so keep your form in else part.

So :-

if(isset($_POST["config_btn"])){
  echo "isset";
  //Some Database writing
}else{
  echo "is not set";
}
  1. When page loaded it's goes to else condition and will echo "is not set";
  2. When you click on submit POST values found and it's runs your query.
  3. if you redirect page again then again post values will be end and goes to else.

Upvotes: 2

Related Questions