[英]PHP How to Redirect to Another Page with Apache Server?
我正在嘗試重定向到另一個頁面:這個想法是創建一個提交按鈕供用戶點擊它,然后重定向到另一個也有數據庫記錄(MySQL 數據庫)的頁面。
更新:我正在使用自處理表單和具有不同功能的幾個提交按鈕。
這是我的代碼有問題:
//Redirect and for user to delete particular record(s)
if(isset($_POST['delete'])){
$query="DELETE FROM Student WHERE StudentId='$id'";
$qresult=mysqli_query($link,$query);
if($qresult){
header("HTTP/1.1 301 Moved Permanently");
$redirect='/RedirectedPage.php';
header('Location:'.$redirect,true,303);
exit;
}
}
如您所見,我正在使用 header() 進行此操作,但它不會重定向,相反,當前頁面僅刷新自身。
數據庫鏈接成功,查詢似乎沒問題...
因此,我想知道出了什么問題?
只需將您的表單提交到另一個頁面
<form action="delete.php"> <input name="delete" type="submit" value="delete"> </form>
所以你的 php 代碼應該在 delete.php 文件中
您也可以將代碼更改為此
//Redirect and for user to delete particular record(s) if(isset($_POST['delete'])){ $query="DELETE FROM Student WHERE StudentId='$id'"; $qresult=mysqli_query($link,$query); if($qresult){ header("Location: RedirectedPage.php"); exit; } }
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.