Hello, fellow PHP experts. I have a script that just isn’t working for me. It consists of a remove button that
posts to the same page when clicked. And then if(isset($_POST[“submit”])), it will try to delete and unlink()
the image from the server, then delete the image path from the database. But what happens when I test it out?
[php]
<?php session_start(); $userid = $_GET["id"]; try { $conn = new PDO("mysql:dbname=users;host=localhost", "register", "mysql" ); $sql = $conn->prepare("SELECT * FROM uploads WHERE id = ? "); $sql->execute(array($userid)); $sql->execute(); while ($result = $sql -> fetch()) { ?><?php echo $result ["Title"]; ?>
<?php echo $result ["Description"]; ?>
<img src = “http://68.192.202.0:87/uploads/<?php echo $result ["Directory"]; ?>” height = “500” width = “600” />
<?php if ($userid == $_SESSION["id"]) { ?> <?php } if (isset($_POST["delete"])) { $file = $result ["Directory"]; unlink("uploads/" . $file); $msql = $conn->prepare("DELETE FROM uploads WHERE Directory = ?"); $msql->execute(array($file)); $msql->execute(); } } } catch(PDOException $e) { echo $e->getMessage(); $conn = null; } ?>[/php]
can you check to see whats wrong with my code? thanks so much