删除php表单中的图像

时间:2012-12-11 09:22:47

标签: php mysql

我有一张表格来编辑有关餐厅的数据。然后,在表单内部我放了一个按钮来删除图像。这是我的代码:

echo "<form name='form_update1' method='post' action='editrestaurant_post.php' enctype='multipart/form-data' >\n";

echo '<table width="50%">';
echo '<tr>';
echo '<td>Edit Restaurant</td>';
echo '</tr>';

echo '<tr>';
echo "<td>&nbsp;</td>";
echo '</tr>';

while ($fp = mysql_fetch_array($rsP)) { // loop as long as there are more results
$proid = mysql_real_escape_string($fp['proid']);
$proid = is_array($proid) ? $proid[count($proid)-1] : $proid;

echo '<tr>';
echo "<td>&nbsp;</td>";
echo "<td><input type='hidden' size='40' name='proid[$p]' value='{$fp['proid']}' /></td>";
echo '</tr>';


echo '<tr>';
echo "<td>Restaurant Name :</td>";
echo "<td><input type='text' size='40' name='resName[$p]' value='{$fp['resName']}' /></td>";
echo '</tr>';


$sqlPi= "SELECT * FROM pimage WHERE pimage.proid ='" . $proid . "'";
        $rsPi = mysql_query($sqlPi) or die($sqlPi."<br/><br/>".mysql_error());
        $pi = 0;

while ($fpi = mysql_fetch_array($rsPi)) { 
$image = mysql_real_escape_string($fpi['image']);
$image = is_array($image) ? $image[count($image)-1] : $image;
$id = mysql_real_escape_string($fpi['id']);
$id = is_array($id) ? $id[count($id)-1] : $id;


echo "<form method='post' action='delete_image.php'>\n";

echo '<tr>';
echo "<td>Image :</td>";
echo "<td><img src='client_images".$fpi['image']."' width='50' height='50' ><input type='submit' name='deletepi' id='deletepi' value='Delete Image'></td>";
echo "<td><input type='hidden' size='40' name='imid' value='{$id}' /><input type='hidden' size='40' name='dir' value='{$image}' /><input type='hidden' size='40' name='e' value='{$e}' /></td>";
echo '</tr></form>';
++$pi;

}




++$p;
}



echo'<tr>
<td colspan="3" align="center"><input type="submit" name="button1" id="button1" value="Submit1"></td>
</tr>
</table>
</form>';

问题是,当我点击删除按钮时,它会像主编辑餐厅表单一样进行操作。我该怎么解决这个问题?谢谢:D非常感谢您的帮助

2 个答案:

答案 0 :(得分:0)

问题是因为你有嵌套的<form>元素。使用单个<form>或创建单独的不使用嵌套的<form>元素。

答案 1 :(得分:0)

如评论中所述,使用单独的表格;或者对于图片删除使用<a>标记并将其链接到delete_image.php。还附加图像的链接,如图像ID。所以在delete_image.php中你可以读取查询字符串并删除相应的图像。