我有一個頁面從數據庫中檢索培訓廣告列表並顯示在表格中。另一個頁面顯示訓練名稱時點擊訓練的詳細信息。詳細信息頁面還允許編輯和刪除廣告。當廣告被編輯或刪除時,頁面被重定向到廣告列表。問題在於,如果我編輯廣告,並且在重定向到廣告列表頁面時刪除廣告,則不會訪問其他頁面,但刪除的廣告仍在列表中。但是,如果我刪除廣告而無需進行編輯,或者如果我訪問了另一個頁面,則可以在編輯完成後返回並刪除廣告,一切正常。對不起,很長的問題。任何形式的幫助表示讚賞。 代碼如下。如果第一個提交的頁面上的第二個PHP頁面沒有刷新目標頁面
廣告列表頁:
$connect = mysqli_connect($host,$user,$password,$database) or die ("Couldn't connect database");
$sql = "SELECT * FROM ad WHERE trainer_id=$trainer_id ORDER BY id desc ";
$result = mysqli_query($connect,$sql) or die("Couldn't execute query.");
$count=mysqli_num_rows($result);
$totalPages=ceil($count/$result_per_page);
$sql = "SELECT * FROM ad WHERE trainer_id=$trainer_id ORDER BY id desc LIMIT $start, $result_per_page ";
$result = mysqli_query($connect,$sql) or die("Couldn't execute query.");
if($count!=0)
{
echo "<table cols='4' cellspacing='25'>";
echo "<th>Training Name</th>";
echo "<th>Trainer/Training Center</th>";
echo "<th>Training Dates</th>";
echo "<th>Registration Starts</th>";
echo "<th>Viewed</th>";
while($row=mysqli_fetch_assoc($result))
{
extract($row);
echo "<tr><td ><a href='personal_ad_details.php?id=$id'>$training_name</a></td>";
echo "<td >$trainer_name</td>";
echo "<td >$training_start - $training_end</td>";
echo "<td >$reg_start</td>";
echo "<td >$view</td></tr>";
}
echo "</table>";
廣告詳情頁(編輯和刪除):
$connect = mysqli_connect($host,$user,$password,$database) or die ("Couldn't connect database");
if(isset($_GET['id']) && !empty($_GET['id'])){
$currentID = $_GET['id'];
$sql = "SELECT * FROM ad WHERE id=$currentID";
$result = mysqli_query($connect,$sql) or die("Couldn't execute query.");
$row= mysqli_fetch_array($result);
extract($row);
echo "<div id='ad_header'>";
echo "<h2>
$training_name</h2>";
echo "<p>Trainer/Training Center:</p> $trainer_name ";
echo "<p>Training Date(s): </p>$training_start - $training_end";
echo "<p>Registration starts: </p>$reg_start";
echo "<p>Phone: </p>$mobile";
if($email!=''){echo "<p>Email: </p><a href='mailto:$email'>$email</a>";}
if($website!=''){echo "<p>Web Site: </p><a href='http://$website' target='_blank'>$website</a>";}
echo "</br>";
echo "</div>";
echo "<div id='ad_main'>";
echo "<p>Training details:</p> </br>"?> <form action="<?php echo htmlspecialchars('personal_ad_details.php')?><?php echo "?id=".$currentID?>" method="post"> <textarea style="position:relative; left:0%" rows="10" cols="25" name="Telim_Melumatlari" ><?php echo $training_details; ?></textarea>
<?php
echo "</div>";
}
?>
<input style="margin:10px" type="submit" name="update" value="UPDATE"></form>
<?php
if(isset($_POST['update']))
{
include('misc.inc');
$connect = mysqli_connect($host,$user,$password,$database)
or die ("Couldn't connect to database.");
$sql = "UPDATE ad SET training_details='$_POST[Telim_Melumatlari]' WHERE id=$currentID ";
mysqli_query($connect,$sql) or die("Couldn't execute query");
$url="personal_ad_list.php";
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
echo '</noscript>'; exit;
}
?>
<form action="<?php echo htmlspecialchars('personal_ad_details.php')?><?php echo "?id=".$currentID?>" onSubmit="return confirm('Are you sure you want to delete the Ad?');" method="post"><input style="margin:10px; background-color:red" type="submit" name="delete" value="DELETE AD"></form>
<?php
if(isset($_POST['delete']))
{
include('misc.inc');
$connect = mysqli_connect($host,$user,$password,$database)
or die ("Couldn't connect to database.");
$sql = "DELETE FROM ad WHERE id=$currentID ";
mysqli_query($connect,$sql) or die("Couldn't execute query");
$url="personal_ad_list.php";
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
echo '</noscript>'; exit;
}
?>
@DincaAdrian也許你有關於解決方案:) –