HTML表单提交不适用于PHP

HTML表单提交不适用于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!

我的php代码有点问题。 该代码包含一个重新加载文档的表单。 但在reaload之后我无法读取POST数据。 这是HTML代码: p>

 &lt; form action =“config_page.php”method =“post”&gt; 
 ... some inputs&n&lt; input type  =“submit”value =“保存”name =“config_btn”class =“submitbtn_2”&gt; 
&lt; / form&gt; 
  code>  pre> 
 
 

在config_page.php之上 我有这个PHP代码: p>

  if(isset($ _ POST [“config_btn”])){
 echo“isset”; 
 //一些数据库写入
  } else {
 echo“未设置”; 
} 
  code>  pre> 
 
 

奇怪的是,提交表单后始终显示输出“未设置”,但数据库 无论如何都会应用更改...(仅当isset语句为true时才执行数据库更改) p>

有人能解决问题吗? p>

谢谢 您的帮助! p> div>

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.