我创建了一个代码来删除文件夹中的图像,并将数据库中的 image_path 更新为 null。尽管图像删除图像,但路径不会更新为空。我花了几个小时才发现我的错误。但我做不到。任何帮助将不胜感激!
这是我的代码
<?php
//this is were images displayed
$sql = "SELECT * FROM services WHERE user_name='wendi'";
$result = $con->query($sql);
if ($result->num_rows > 0) {
// output data of each row
while ($row = $result->fetch_assoc()) {
?>
<a href="delete.php?delete=<?= $row['id'] ?>" onclick = "return confirm('Are you sure you want to delete?')"><img src="images/template/delete.png" id="AEDbutton">delete</a>
<?php
echo "<img border=\"0\" src=\"" . $row['image_path4'] . "\" width=\"200\" height=\"100\">";
echo "<br>";
}
}
?>
这是 delete.php
<?php
include('config.php');
$sql = "SELECT * FROM services WHERE user_name='wendi'";
$result = $con->query($sql);
while ($row = $result->fetch_assoc()) {
$image = $row['image_path4'];
unlink($image);
}
$sql = "UPDATE image_path4=null, file_name4=null FROM services WHERE user_name='wendi'";
$result = $con->query($sql);
?>
最佳答案
看来您的UPDATE
查询格式不正确,the syntax应该是这样的:
UPDATE {table} SET {column}={value} WHERE {column2}={value2}
所以在你的情况下,这将是:
UPDATE services SET image_path4=null, file_name4=null WHERE user_name='wendi'
关于php - 文件夹中的图像已删除,但图像路径未在 PHP 中更新为 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51979869/