我有一个页面,可以从数据库中检索培训广告列表并显示在表格中。另一页显示了点击培训名称时有关培训的详细信息。详细信息页面还允许编辑和删除广告。在编辑或删除广告时,页面会重定向到广告列表。问题是,如果我在重定向到广告列表页面时删除了广告,则在编辑广告而不访问其他页面时,已删除的广告仍会在列表中。但是,如果我删除广告而不进行编辑或在编辑后如果我访问其他网页,则返回并删除广告,一切正常。对不起,很长的问题。任何形式的帮助表示赞赏。 代码如下。
广告列表页面:
$newData = $data->flatten()->filter(function($val) {
return $val->competitorId === "someIdid"
)}
广告详情页面(编辑和删除):
$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>";
答案 0 :(得分:0)
您应该检查您的表单操作网址:
<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">
要
<form action="" onSubmit="return confirm('Are you sure you want to delete the Ad?');" method="post">
注意:另外一个好的做法是你应该从页面开始提交流程代码:
<?php
$connect = mysqli_connect($host,$user,$password,$database) or die ("Couldn't connect database");
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;
}
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;
}
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="" 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>
<form action="" 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>