Php 提交表单后刷新页面
我有个小问题。我想在提交表单后重新加载页面Php 提交表单后刷新页面,php,html,Php,Html,我有个小问题。我想在提交表单后重新加载页面 <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="upd
<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>
在
中,action属性应该是action=“”
您可以使用:
<form method="post" action=" " onSubmit="window.location.reload()">
您想要一个可以自行提交的表单吗?然后将“action”参数留空
比如:
如果要使用此页面处理表单,请确保表单或会话数据中有某种机制来测试表单是否正确提交,并确保您没有尝试处理空表单
您可能需要另一种机制来决定表单是否已填写并提交,但是否无效。我通常使用一个与会话变量匹配的隐藏输入字段来决定用户是单击了提交还是第一次加载页面。通过每次指定一个唯一的值并将会话数据设置为相同的值,如果用户单击“提交”两次,也可以避免重复提交 如果希望在同一页面上提交表单,请从表单属性中删除操作
<form method="POST" name="myform">
<!-- Your HTML code Here -->
</form>
仅限使用
echo "<meta http-equiv='refresh' content='0'>";
echo”“;
就在插入查询之前}
范例
if(isset($\u POST['submit']))
{
SQL查询----
回声“;
}
//在结束html标记后的末尾插入此php代码。
哈哈,我只是想知道为什么没有人知道:
我使用它,所以如果用户刷新页面,就不会提示他重新提交数据
有关更多详细信息,请参见您的目标是什么?这是默认行为,不是吗?你为什么要在行动中体现这一价值?我认为这是错误的。我的目标是,当我提交之后,谁会刷新我所在的页面moment@DárioViegas if“”“
是一个错误,应该是”“
,您的问题现在解决了吗?我想我有一个答案给您!您解决问题了吗?如果您希望在单击“提交”后刷新页面,请使用HTML
中的第一个。如果要在单击“提交”后更改页面,请使用第二个选项。这是你的选择。很好,这真的帮了我的忙!这是一个真正的“刷新”,因此回答了这个问题,而其他许多答案都需要创建一个新的URL作为$location。对于在URL中有几十个变量的人来说,这可能会很费时,也很烦人,等等。嘿,这对我来说很有效,非常好。但是,它现在会刷新两次,一次是从表单刷新,但实际上刷新并不起作用。另一个来自回显代码。你是否设法阻止了第一个刷新?请看看这个解决方案:它对我来说是最好的,是的
<form method="post" action="">
<table>
<tr><td><input name="Submit" type="submit" value="refresh"></td></tr>
</table>
</form>
<?php
if(isset($_POST['Submit']))
{
header("Location: http://yourpagehere.com");
}
?>
<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
// 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
?>
echo "<meta http-equiv='refresh' content='0'>";
if(isset($_POST['submit']))
{
SQL QUERY----
echo "<meta http-equiv='refresh' content='0'>";
}
//insert this php code, at the end after your closing html tag.
<?php
//setting connection to database
$con = mysqli_connect("localhost","your-username","your-
passowrd","your-dbname");
if(isset($_POST['submit_button'])){
$txt_area = $_POST['update'];
$Our_query= "INSERT INTO your-table-name (field1name, field2name)
VALUES ('abc','def')"; // values should match data
// type to field names
$insert_query = mysqli_query($con, $Our_query);
if($insert_query){
echo "<script>window.open('form.php','_self') </script>";
// supposing form.php is where you have created this form
}
} //if statement close
?>
header("Refresh: 0"); // here 0 is in seconds