homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

PHP multiple delete with check box

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


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)

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)

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)

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).

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved