我正在尝试创建一个允许用户删除他们留下的帖子的功能。基本上我正在尝试选择一个 ID,然后将其传递给另一个函数以将其删除。当前的代码正在删除每条评论,而不仅仅是像我尝试的那样链接到 ID 的评论。
这是表格值
Table eventUpdates
ID - unique ID. Trying to use this value to delete the post
eventID - references an eventID from another table
eventReply - the "message" or response
eventUserID -ID of the user posting the message
username -username of the person
eventTimestamp -timestamp
因此,目前每个回复都被删除。我不能让它只删除我发送的 ID。
<table border ="1">
<?
$eventUpdates = mysql_query($sql);
while ($list = mysql_fetch_assoc($eventUpdates)) {
echo $updateID;
echo '<tr><td>';
echo $list['username'],"</br>", $list['eventTimestamp'],'<br/>';
if($list['eventUserID'] == $userid){ //used for deleting posts. Checks the session to make sure it's the user who made the post
?>
<form method="post">
<input type="submit" name="deleteUpdate" value="Delete Update">
</form>
<?
if(isset($_POST['deleteUpdate'])){
$updateID = $list['ID'];
$delete = new postprocessing;
$delete->deleteEventUpdate($updateID);
echo '<meta http-equiv="refresh" content="0;url=main.php">';
}
}
echo '</td><td>';
echo $list['eventReply'];
echo '</td></tr>';
}
这是用于删除它的函数
function deleteEventUpdate($ID){
mysql_query("delete from eventUpdates where ID = '$ID'");
}