Jump to content

delete buttons on form not working


bcamp1973

Recommended Posts

i have the following script at the top of the page and the form below on that same page. it works in Safari and FireFox on both PC and Mac. However, in IE the page just reloads and nothing gets deleted. Any suggestions?

 

if($_POST['delete']) {
$query='DELETE FROM addresses WHERE id='.$_POST['delete'];
mysql_query($query) OR die(mysql_error());
}

 

<form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post">
<ul>
<li>Potter, Harry<input type="image" name="delete" value="2" src="assets/img/delete.gif" /></li>
<li>Bar, Foo<input type="image" name="delete" value="8" src="assets/img/delete.gif" /></li>
<li>Smith, John<input type="image" name="delete" value="9" src="assets/img/delete.gif" /></li>
</ul>
</form>

Link to comment
https://forums.phpfreaks.com/topic/44411-delete-buttons-on-form-not-working/
Share on other sites

The name is conflict with each other. Use name="delete[]" instead and do this:

 

if(isset($_POST['delete'])) {
     if (is_array($_POST['delete'])) {
        foreach ($_POST['delete'] as $val) {
        	$query='DELETE FROM addresses WHERE id='.$val;
        mysql_query($query) OR die(mysql_error());
         }
     }
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.