我有一点问题.我想在提交表单后重新加载我的页面.
<form method="post" action="">
<textarea cols="30" rows="4" name="update" id="update" maxlength="200" ></textarea>
<br />
<input type="submit" value=" Update " id="update_button" class="update_button"/>
</form>
Run Code Online (Sandbox Code Playgroud)
小智 48
只用
echo "<meta http-equiv='refresh' content='0'>";
Run Code Online (Sandbox Code Playgroud)
插入查询之后}}例子
if(isset($_POST['submit']))
{
SQL QUERY----
echo "<meta http-equiv='refresh' content='0'>";
}
Run Code Online (Sandbox Code Playgroud)
can*_*say 11
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <!-- notice the updated action -->
<textarea cols="30" rows="4" name="update" id="update" maxlength="200" ></textarea>
<br />
<input name="submit_button" type="submit" value=" Update " id="update_button" class="update_button"/> <!-- notice added name="" -->
</form>
Run Code Online (Sandbox Code Playgroud)
在你的整页上,你可以拥有这个
<?php
// check if the form was submitted
if ($_POST['submit_button']) {
// this means the submit button was clicked, and the form has refreshed the page
// to access the content in text area, you would do this
$a = $_POST['update'];
// now $a contains the data from the textarea, so you can do whatever with it
// this will echo the data on the page
echo $a;
}
else {
// form not submitted, so show the form
?>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <!-- notice the updated action -->
<textarea cols="30" rows="4" name="update" id="update" maxlength="200" ></textarea>
<br />
<input name="submit_button" type="submit" value=" Update " id="update_button" class="update_button"/> <!-- notice added name="" -->
</form>
<?php
} // end "else" loop
?>
Run Code Online (Sandbox Code Playgroud)
哈哈,我只是想知道为什么没有人知道PHP 头函数:
header("Refresh: 0"); // here 0 is in seconds
Run Code Online (Sandbox Code Playgroud)
我使用这个,所以如果用户刷新页面,不会提示重新提交数据。
有关更多详细信息,请参阅使用 PHP 刷新页面
如果要在同一页面上提交表单,请action从表单属性中删除。
<form method="POST" name="myform">
<!-- Your HTML code Here -->
</form>
Run Code Online (Sandbox Code Playgroud)
但是,如果要在从另一个文件提交表单后重新加载页面或重定向页面,则可以调用此函数php,它将在0秒内重定向页面。此外,header如果需要,您可以使用,只需确保没有任何内容,然后再使用header
function page_redirect($location)
{
echo '<META HTTP-EQUIV="Refresh" Content="0; URL='.$location.'">';
exit;
}
// I want the page to go to google.
// page_redirect("http://www.google.com")
Run Code Online (Sandbox Code Playgroud)