I’m attempting to make a function that will allow users to delete posts they have left. Basically I’m trying to select an ID and then pass it off to another function to delete it. The current code is deleting every comment, not just the comment linked to the ID like I’m attempting to.
Here are the table values
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
So, currently every response is being deleted. I can’t get it to delete just the ID that I send.
<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>';
}
Here is the function used to delete it
function deleteEventUpdate($ID){
mysql_query("delete from eventUpdates where ID = '$ID'");
}
This is because you haven’t specified the ID you want to delete in the post array, so every comment they created “matches” the deletion criteria. The
$_POSTarray looks like:$_POST = array(‘deleteUpdate’=’Delete Update’);
so when you’re looping through the list of events, every comment that the user ‘owns’ (
$list['eventUserID'] == $userid) matches the criteria “isset($_POST['deleteUpdate'])“:You need to include a hidden input with the ID the specific comment you want to delete and match against it as well:
and then in the loop: