I am using a simple way to have confirmation box when deleting a record, problem here is I couldn't find where to place header
code for redirecting to some other page after deletion. I have placed it after executing query and get this error
Cannot modify header information - headers already sent by (output started at ...
and I am not redirected to required page, but somehow on reloading page record wasn't there it was deleted.
if(isset($_POST['submit'])){
$que=$db->prepare("DELETE FROM blogs WHERE blogs_id = :blogId");
$que->execute(array(':blogId'=>$blogId));
header("location:front.php");
}
<form method="POST">
<input type="submit" name="submit" value="Delete" onclick="return confirm("Are you sure you want to delete this?")" />
</form>
replace
header("front.php");
with
echo "<script> window.location='front.php';</script>";
使用元刷新标签而不是标题来重定向页面
<meta http-equiv="refresh" content="0;url=http://example.com">
you need to use header("location:front.php");
instead of header("front.php");
//but before header there should not be any echo or print otherwise it will not redirect.
your input for confirmation is wrong change it to this:
<input type="submit" name="submit" value="Delete" onclick='return confirm("Are you sure you want to delete this?")' />
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.