<?php
$servername = "49.12.125.236";
$username = "patiltec_anand";
$password = "Asd123!@#";
$database = "patiltec_loginsystem1";
$conn = new mysqli($servername, $username, $password, $database);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
?>




<?php
if (isset($_POST['delete'])) {
    $checkbox = $_POST['checkbox'];

    foreach ($checkbox as $id) {
        $sql = "SELECT image FROM postsbyusers WHERE id = '$id'";
        $result = $conn->query($sql);
        if ($result->num_rows > 0) {
            $row = $result->fetch_assoc();
            $filename = $row['image'];

            $path = "../images/".$filename;
            $path2 = "../images/thumbs/".$filename;
            if (file_exists($path)) {
                unlink($path) ;
                unlink($path2) ;
                echo "<center><b> Record deleted successfully.</b></center>";
            } else {
                echo "Image not found.<br>";
            }
        }
    }
}
?>



<?php
if (isset($_POST['delete'])) {
    $checkbox = $_POST['checkbox'];
    foreach ($checkbox as $id) {
        $sql = "DELETE FROM postsbyusers WHERE id = '$id'";
        if ($conn->query($sql) === TRUE) {
            echo "<center> <b><span style='color:red;'> User Record deleted successfully.</span> </b> </center>";
            echo"<meta http-equiv = 'refresh' content='3; url = allinone2.php'>";
        } else {
            echo "Error deleting record: " . $conn->error . "<br>";
        }
    }
}
?>



<!DOCTYPE html>
<html>
<head>
<title>allinone2</title>
<meta name="viewport" content="width=device-width, initial-scale=1">

 <link rel="stylesheet" href="/db71/gradientbg.css">

  <link href="img/logsys13.png" rel="icon">
  <link href="img/logsys13.png" rel="apple-touch-icon">
</head>

<body class="bg17" style="margin:30px auto; max-width:600px;">
    
<div style='background: rgba(255,255,255,0.7); floadt:left; margin:9px; padding:2px; font-size:18px; border-radius:15px;'>
<form method="POST" action="" style='font-family:arial;'>
<input type="submit" name="delete" value="Delete" style="font-size:22px; cursor:pointer; position:fixed; top:5px; left:40%;">
<ol>
<?php
$sql = "SELECT * FROM postsbyusers";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $id = $row['id'];
        $name = $row['name'];
        $subject = $row['subject'];
        $image = $row['image'];
        //$image_text = $row['image_text'];
        echo "<div style='floadt:left;'><li>";
        echo "<input type='checkbox' name='checkbox[]' value='$id' style='height:20px; width:20px;'> <span style='color:red;'> $subject </span>
        <!-- <span style='color:red;'> $image_text </span>-->  image-<a href='../images/$image'>$image </a>
        <!-- <img src='../images/thumbs/$image' width='50' height='50' valign='middle' vspace='5px'> --> <hr>";
        echo "</li></div>";

    }
}
?>
<ol>
</form>
</div>


</body>  
</html> 


