此表显示了用户在我的网站上添加的所有“景点” - 一个可以记录的库。他们可以通过点击'empty_trash-26.png'图像删除任何这些'景点'。哪个链接到drop_attraction.php
我的问题是,当用户去删除他们已添加的“吸引力”时,它会删除添加到网站/数据库中的最新“吸引力”。我假设在while循环中,$ _SESSION ['attraction_id']每次被最新实体覆盖。
有谁知道我怎么能阻止这个? - 所以他们可以删除他们想要的任何东西,而不仅仅是最新的!
// Connects to my Database
include "Config.php";
$dataA = mysql_query("SELECT * FROM Attractions WHERE user_id = ".$_SESSION['id']."") or die(mysql_error());
// HEADER OF TABLE
Print "<table id="."box-table-a"." summary="."Deals".">";
Print "<thead>";
Print "<tr>";
Print "<th scope="."col".">Categories</th>";
Print "<th scope="."col".">Item Name</th>";
Print "<th scope="."col".">Price</th>";
Print "<th scope="."col"."> </th>";
Print "</tr>";
Print "</thead>";
// ATTRACTIONS
while($infoA = mysql_fetch_array($dataA))
{
Print "<tbody>";
Print "<tr>";
Print "<td>"."Attractions"."</td>";
Print "<td>".$infoA['attraction_name'] . "</td>";
Print "<td>".$infoA['attraction_price'] . " </td>";
$_SESSION['attraction_id'] = $infoA['id'];
$_SESSION['attraction_name'] = $infoA['attraction_name'];
$_SESSION['attraction_price'] = $infoA['attraction_price'];
Print "<td><a href="."drop_attraction.php"."> <img src="."images/empty_trash-26.png"." width="."20"." height="."20"."></a></td>";
Print "</tr>";
Print "</tbody>";
}
Print "</table>";
下面是drop_attraction.php页面 - 一旦点击'empty_trash-26.png',php页面将重定向到此页面,因此可以在我的数据库的'Attractions'表中删除该行。完成后,将其直接链接回“dashboard-library.php”页面(上面显示的代码)
include "config.php";
mysql_query("DELETE FROM Attractions WHERE id=".$_SESSION['attraction_id']."");
header('Location: /dashboard-library.php');
答案 0 :(得分:0)
您的带有景点表的页面应该将ID传递到放置景点页面:
Print "<td><a href="."drop_attraction.php?id=".$infoA['id']."> <img src="."images/empty_trash-26.png"." width="."20"." height="."20"."></a></td>";
drop_attractions.php
include "config.php";
mysql_query("DELETE FROM Attractions WHERE id=".mysql_real_escape_string($_GET['id']));
header('Location: /dashboard-library.php');