我试图在查询执行后立即刷新页面。该页面能够显示弹出消息“成功”。但是,它无法正确刷新页面,只能无限显示弹出消息。当前网页的网址是http://localhost/test/test.php?post=1
PHP刷新页面有'?var = value'
<form method="post" role="form" action="reply.php">
<fieldset>
<div class="form-group">
<textarea name="reply" class="form-control" rows="3" placeholder="Comment" required autofocus=""></textarea>
</div>
<button name="post" type="submit" class="[ btn btn-success ]" data-loading-text="Loading...">Post reply</button>
</fieldset>
</form>
reply.php
if (isset($_POST['post'])) {
$description =$_POST['reply'];
$stmt = "INSERT INTO reply (comments) VALUES (:description)";
$p = $MySQLi_CON -> prepare($stmt);
$results = $p -> execute(array(
":description" => $description
));
echo '<script language = "javascript">';
echo 'alert("Successful")';
echo '</script>';
echo "<script> location.reload(true); </script>";
if(!$results){
echo '<script language = "javascript">';
echo 'alert("Fail")';
echo '</script>';
echo "<script> location.reload(true); </script>";
}
}
JavaScript的JavaScript头?只需使用:header('location:URL to same page');或者你可以使用jQuery与Ajax,这也是一个更好的解决方案,然后在PHP中使用JavaScript! – Soheyl
我试图找到相同的页面,它是http://localhost/test/test.php?post = 1。如果我尝试了这种方法,它只会去http://localhost/test/test.php – fypforstack
谁说的?!你可以在标题的URL中使用任何你想要的东西!只需使用:header('location:localhost/test/test.php?post = 1'); – Soheyl