我创建了一个画廊管理。 我用While循环打印了图像缩略图。 我可以通过复选框选择要删除的照片,然后提交表单。 当我发送表单时,页面刷新,她运行图像unlink(),删除行查询, 但我仍然看到图像的打印行404(未找到)。 如果我刷新另一个,那就行了!
代码:
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
//while loop
</form>
<?php
if (isset($_POST['delete'])) {
$delete = $_POST['select'];
foreach ($delete as $id => $val) {
$query="SELECT foto FROM gallery WHERE id = '$val'";
$result1= mysql_query($query);
while($row = mysql_fetch_assoc($result1)) {
unlink($output_dir . $row[foto]);
}
$query="DELETE FROM gallery WHERE id = '$val'";
$result2= mysql_query($query) or die (mysql_error());
}
}
解决。 编辑:
if (isset($_POST['delete'])) {
$delete = $_POST['select'];
foreach ($delete as $id => $val) {
$query="SELECT foto FROM gallery WHERE id = '$val'";
$result1= mysql_query($query);
while($row = mysql_fetch_assoc($result1)) {
unlink($output_dir . $row[foto]);
}
$query="DELETE FROM gallery WHERE id = '$val'";
$result2= mysql_query($query) or die (mysql_error());
}
}
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
//while loop
</form>
答案 0 :(得分:1)
你必须在php代码之后编写表单
答案 1 :(得分:0)
您应该在HTML部分之前运行PHP代码。
试试这个:
<?php
if (isset($_POST['delete'])) {
$delete = $_POST['select'];
foreach ($delete as $id => $val) {
$query="SELECT foto FROM gallery WHERE id = '$val'";
$result1= mysql_query($query);
while($row = mysql_fetch_assoc($result1)) {
unlink($output_dir . $row[foto]);
}
$query="DELETE FROM gallery WHERE id = '$val'";
$result2= mysql_query($query) or die (mysql_error());
}
}
?>
<form name="form" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
//while loop
</form>