我使用兩個腳本,一個用於從SQL中刪除,另一個用於添加到數據庫。使用標題時,從一個腳本刷新數據,而不是從另一個腳本?
我遇到的問題是,在運行添加腳本時,它將刷新即時顯示更改的頁面。然而,在運行刪除腳本時,它不會立即刷新它,似乎它會緩存輸出?
如果它確實緩存了它重定向到的輸出,爲什麼一個腳本顯示添加而另一個不顯示刪除?
添加腳本
// Set a URL for the user to be redirected to
$header_URL = "Location: ".WEBURL.DOCROOT."pages/parents-evening/{$_SESSION['status']}/";
// SQL statement using the variables from the user to insert into a specific table
$sql = "INSERT INTO $table ($columns) VALUES ($values);";
// Check that the query was successful
if(mysqli_query($conn, $sql))
{
// Success
// Closes the database connection
mysqli_close($conn);
// Sets the redirect location
header($header_URL);
// Exits the script
exit();
}
else
{
// Fail
// Closes the database connection
mysqli_close($conn);
// Sets the redirect location
header($header_URL);
// Exits the script
exit();
}
刪除腳本
// Set a URL for the user to be redirected to
$header_URL = "Location: ".WEBURL.DOCROOT."pages/parents-evening/{$_SESSION['status']}/";
// SQL statement to delete from the table provided where the ID is equal to either the POST or GET value
$sql = "DELETE FROM {$table} WHERE id = {$_POST['delete_id']}{$_GET['delete_id']}";
// Check the query was successful
if(mysqli_query($conn, $sql))
{
// Success
// Closes the database connection
mysqli_close($conn);
// Sets the redirect location
header($header_URL);
// Exits the script
exit();
}
else
{
// Fail
// Closes the database connection
mysqli_close($conn);
// Sets the redirect location
header($header_URL);
// Exits the script
exit();
}
「當我刪除它不會」 這並不_what_?你繼續說它最終會刷新,所以它沒有做什麼? –
@PatrickQ我已經重寫了我的問題。但是,當一個腳本運行時它會立即刷新,另一個腳本不會立即執行。 –
爲什麼你有'{$ _POST ['delete_id']} {$ _ GET ['delete_id']}''有特定的原因嗎?我只希望其中的一個。你真的應該看看參數綁定。 –