$sql = "DELETE FROM `threads` WHERE thread_user_id = $userId and thread_id = ?";
$stmt = $conn->prepare($sql);
$stmt->bind_param($thread_id); // thread_id should be in $_POST['thread_id'] and you should use POST not GET for this action (use form instead of link)
$stmt->execute();
Aug 6, 2023
2
Level 20
How to delete a post which is belongs to the logged in user? In PHP
if a logged in user is having more than 1 post and when a user click on the particular post for delete it how to achieve it in php. my code query
$userId = $_SESSION['user_id'];
$sql = "SELECT thread_id FROM `threads` WHERE thread_user_id = $userId";
$result = mysqli_query($conn, $sql);
$data = mysqli_fetch_assoc($result);
here is my thread link to delete it
<p class="small mb-0" style="color: #aaa;">
<?php echo $data['thread_id'] ?> //by this i am getting only 1st post id ,
// if i will use foreach loop to get all id but then i will get all the id on the same link
<a href="/thread?thread_id=<?php echo $data['thread_id'] ; ?>" class="link-grey">Remove</a>
</p>
when a user click on the remove link it should remove the specific post on which user is clicking based on that post id or something
Please or to participate in this conversation.