gpt4 book ai didi

php - 在数据库中搜索到图片后如何删除它?

转载 作者:行者123 更新时间:2023-11-29 19:11:11 25 4
gpt4 key购买 nike

作为管理员,我想在搜索图片后从我的网站删除图片。但它不会删除文件($target)。

<nav>
<a href="../Home/frontEnd.php"><img class="icon" src="../Logo/Home.png" /></a>
<a href="../Search/search.php"><img class="icon" src="../Logo/Search.png" /></a>
<a href="../Upload/upload.php"><img class="icon" src="../Logo/Camera.png" /></a>
<a href="../Super/supervisor.php"><img class="icon" src="../Logo/Supervisor.png" /></a>
<a href="../Profile/profile.php"><img class="icon" src="../Logo/Profile.png" /></a>
</nav>

<div class="searchDiv">
<form action="supervisor.php" method="post">
<input type="text" class="search" name="search" placeholder="Zoek een foto..." autocomplete="off">
<br>
<input type="submit" name="submit" id="submitUpload" value="Zoeken">
</form>
</div>

<?php
if(isset($_POST['submit'])) {
$dbc = mysqli_connect('localhost', '22894_opdracht1', '22894_opdracht1', '22894_database') or die ('Error connecting!');
$search = $_POST['search'];
$query = "SELECT * FROM instaclone WHERE description LIKE '%" . $search . "%' OR username LIKE '%" . $search . "%' OR date LIKE '%" . $search . "%'";
$result = mysqli_query($dbc, $query);
while ($row = mysqli_fetch_array($result)){
$target = $row['target'];
$date = $row['date'];
$username = $row['username'];
$description = $row['description'];
echo '<div class="picture">';
echo '<div class="name">';
echo '<div class="date">';
echo $username . '<br>';
echo $date;
echo '</div>';
echo '</div>';
echo '<img class="pictureShow" src="' . $target . '" /><br>';
echo '<p class="beschrijving">' . '<b>' . $username . ': </b>' . $description;
echo '<div class="reactions">';
echo '<form method="post">';
echo '<input type="text" name="reaction" class="reaction" placeholder="Een reactie toevoegen...">';
echo '</form>';
echo '</div>';
echo '</div>';

if(isset($_POST['delete'])) {
$sql = "DELETE FROM instaclone WHERE target LIKE '%" . $target . "%' ";
}
}
mysqli_close($dbc);
}
?>

<div class="deleteDiv">
<form action="supervisor.php" method="post">
<input type="submit" name="delete" id="submitUpload" value="Delete">
</form>
</div>

我想在按下删除提交按钮后删除 $target。

最佳答案

 if(isset($_POST['delete'])) {
$sql = "DELETE FROM instaclone WHERE target = '$target' ";
mysqli_query($dbc, $sql);
echo "$target deleted";

}

关于php - 在数据库中搜索到图片后如何删除它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43071211/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com