Jump to content

Recommended Posts

I'm trying to delete data from database by ticking the checkbox and press the delete button... but it doesn't deems to work.. help pleasee..

<?php
$con = mysql_connect("localhost","root","");
mysql_select_db("test2",$con);

$sql = "select * from member";
$result = mysql_query($sql,$con);
?>

<form action = "deletetest.php" method = "POST">
<?php 
while($row = mysql_fetch_assoc($result))
{
?>
<tr><td><input type = "checkbox" name = "deletebox" value="<?php echo $row['member_ID']; ?>"></td>
<td><?php echo $row['member_ID']; ?></td>
<td><?php echo $row['FirstName']; ?></td>
</tr><br/>


<?php } ?>

<tr><td><input type = "submit" name = "submit" value = "delete"></td></tr>
</form>

<?php 
if($_POST['submit'] == 'submit')
{
foreach($_POST['deletebox'] as $key)
{
$sql2 = "delete from member where member_ID = '$key'";

mysql_query($sql2,$con);
}
}
?>


 

 

Link to comment
https://forums.phpfreaks.com/topic/155780-solved-delete-function-with-checkbox/
Share on other sites

change this

<tr><td><input type = "checkbox" name = "deletebox" value="<?php echo $row['member_ID']; ?>"></td>

to this

<tr><td><input type = "checkbox" name = "deletebox[]" value="<?php echo $row['member_ID']; ?>"></td>

 

and it should work (I think, someone correct me if im wrong ). Hope that helps!

ah i think i see the problem

<tr><td><input type = "submit" name = "submit" value = "delete"></td></tr>
</form>

<?php 
if($_POST['submit'] == 'submit')

the value of the submit button (named submit) is delete, and you are testing to see if its value is submit

 

change the above to

<tr><td><input type = "submit" name = "submit" value = "submit"></td></tr>
</form>

<?php 
if($_POST['submit'] == 'submit')

 

and it should work

 

hope that helped

 

EDIT: Dam too late haha.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.