I want to make a query that deletes a post(thread) from a page but in that page I have multiple posts, I have in my database a field called id_thread is the unique id of every post but I'm listing multiple posts of the same user in the page, this is the code of the page where the posts are listed:
<?
session_start();
if(isset($_SESSION['id']))
{
$servername = "(...)";
$username = "(...)";
$password = "(...)";
$dbname = "(...)";
$connect = mysqli_connect($servername, $username, $password, $dbname);
if (!$connect) {
die("Connection failed: " . mysqli_connect_error());
}
}
else
{
header(" url=index.php");
}
?>
(... hidded non relative html code ....)
<?
$id = (isset($_GET['id'])) ? $_GET['id'] : $_SESSION['id'];
$query = mysqli_query($connect,"SELECT * FROM thread inner join category on thread.id_type=category.id_type WHERE username = '".$id."'");
echo '<div class="container marg-t-100">'."All posts from User: ".$id.'</div>';
echo '<div class="container-fluid marg-t-25">';
while($row = mysqli_fetch_array($query))
{
echo '<div class="col-md-1"></div>';
echo '<div class="col-md-11">';
echo '<form role="form" action="delete.php" method="post"><a type="submit" class="btn btn-danger marg-t-10 pull-right">Delete Thread</a></form>';
echo $row['title'] ."<br><br>".$row['content']."<br><br>".'<div class="pull-right">'. "date: ".$row['data']."<br>"."author: ".$row['username']."<br>".$row['name'].'</div>' ."<br><br><br><hr><br>";
echo '</div>';
}
echo '</div>';
mysqli_close($connect);
?>
(...)
this is an image of the page im talking about:
I want that when I click "Delete Thread" the respective post(thread) gets deleted from database.
If you see in the page code above you can see that the delete button takes action at delete.php, this is my code on that file:
<?php
session_start();
if(isset($_SESSION['id']))
{
$servername = "(...)";
$username = "(...)";
$password = "(...)";
$dbname = "(...)";
$connect = mysqli_connect($servername, $username, $password, $dbname);
$id = (isset($_GET['id'])) ? $_GET['id'] : $_SESSION['id'];
$query = mysqli_query($connect,"Delete FROM thread WHERE username = '".$id."' and id_thread ='".(I WANT THE RELATIVE ID HERE)."'");
if (!$connect) {
die("Connection failed: " . mysqli_connect_error());
}
}
else
{
header(" url=index.php");
}
?>