Php 页面刷新提交我的表单
您的页面仍保留Php 页面刷新提交我的表单,php,submit,page-refresh,Php,Submit,Page Refresh,您的页面仍保留$\u POST值。所以,如果你刷新它。它将再次打印文件 因此,添加标题,如下重定向用户: <?php $rs = mysql_query("SELECT * FROM users WHERE id='$_SESSION[user_id]'"); while ($row= mysql_fetch_array($rs)) { $starter= $row['id']; $user_name= $row['user_name']; } $starterID
$\u POST
值。所以,如果你刷新它。它将再次打印文件
因此,添加标题
,如下重定向用户:
<?php
$rs = mysql_query("SELECT * FROM users WHERE id='$_SESSION[user_id]'");
while ($row= mysql_fetch_array($rs))
{
$starter= $row['id'];
$user_name= $row['user_name'];
}
$starterID=$starter;
$companyID=$_GET['id'];
$input = $_POST['message'];
date_default_timezone_set('Europe/Helsinki');
$timestamp = date('h:i', time());
$file = $companyID." and ".$starterID.".txt";
if (file_exists($file)) {
$file = $companyID." and ".$starterID.".txt";
} else {
$file = $starterID." and ".$companyID.".txt";
}
$current = file_get_contents($file);
$current.= "<b>$user_name</b> <br> $input $timestamp\n<br>";
if(isset($_POST['message'])){
file_put_contents($file, $current);
}
echo $current;
?>
<form action="" method="post">
<input type="text" name="message" autocomplete="off">
<input type="submit">
</form>
我尝试了所有的建议,但不幸的是那些对我不起作用 我做了更多的研究,发现对于这个案例和我来说,最好的解决方案是: 原始代码:
if(isset($_POST['message'])){
file_put_contents($file, $current);
header('Location:Your_File_name.php')
}
解决方案:
if(isset($_POST['message']) && $_POST != null){
file_put_contents($file, $current);
}
if(isset($\u POST['message'])&&&$\u POST!=null){
文件内容($file,$current);
回声'
location.reload();
';
}
感谢您的建议,他们给了我一个更好的搜索方法:)您可以查看最后一条消息是否相同。如果相同,则不执行任何操作。每次刷新时,都会发布以前的内容,因此您的
If(isset($\u POST['message'))
会执行并存储内容。。在脚本的最后一部分使用@Apul Gupta的建议unset($\u POST)
。请不要使用mysql.*
。而是使用或使用。
if(isset($_POST['message']) && $_POST != null){
file_put_contents($file, $current);
echo' <script type="text/javascript">
location.reload();
</script>';
}