Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP multiple delete with check box



3:06 pm on Jun 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member


I have a page with a repeat region from a MySQL database. Along side each entry is a checkbox and when submitted it appends all the ID's where a tick box has been checked to the querystring. I have then used the following code to delete the records. It only deletes 1 record (presumably the first). How do I do about scrolling through. Do i need a loop or something.


Regards and thanks for any suggestions.



3:15 pm on Jun 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

how are you creating the checkboxes?

The best way to do it is by using an array.

so for your form :

echo "<input type='radio' name='f_active[{$row[id]}]' value='X'>";
echo "<input type='radio' name='f_active[{$row[id]}]' value='Z'>";

echo "<input type='hidden' name='oldactive[{$row[id]}]' value='{$row[active]}'";

then pass it to a page that updates the database

foreach ($f_active as $id => $state)
if ($state!=$oldactive[$id])

password stuff etc

$query="UPDATE databse SET active='$state', posted='$date' WHERE id='$id' ";
echo "Record Updated<br>";


11:08 am on Jul 1, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Thanks for the response Knighty. I am still having difficulties though.

The Checkboxes on the first page are created via a loop. I have given them all the same name (ID) and when they post to the second page only the last one is deleted.

Any thoughts, this is not my strong point.


The code on the second page is:

$array = ($ID);
$sql = "DELETE FROM MMUser WHERE UserID IN ($array) ";
$pResult=mysql_query( $sql , $db_connection );
$errMsg = mysql_error();
if( $pResult == false ) {
echo "Error: $errMsg<br />Query: $sql<br />\n";


8:12 pm on Jul 1, 2002 (gmt 0)

10+ Year Member

When you create multiple-select or checkbox elements which are to be processed by PHP, the name you give them must end in a pair of square brackets:

<input type="checkbox" name="check[]" />

That enables the various elements to be accessed as an array (in this case $check[0], $check[1] etc).


Featured Threads

Hot Threads This Week

Hot Threads This Month