-2

I got a form to edit data about restaurant. Then, inside the form I put a button to delete image. This is my code :

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>';

The problem is when I click the delete button, it does action like the main edit restaurant form. How could I solve this? Thanks :D and really appreciate your help

user1822825
  • 53
  • 1
  • 1
  • 7

2 Answers2

0

The problem is because you have nested <form> element. Either use single <form> OR create separate don't use nested <form> element.

Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100
0

As mentioned in the comment use separate forms; or for the picture delete use an <a> tag and link it to delete_image.php. Also append the link of the image like the image id. So in delete_image.php you can read the querystring and delete the corresponding image.

J. Steen
  • 15,470
  • 15
  • 56
  • 63
Ganesh RJ
  • 942
  • 2
  • 19
  • 31