Re: Delete Multiple Records From Checkboxes

From: Date: Thu, 27 May 2004 01:55:26 +0000
Subject: Re: Delete Multiple Records From Checkboxes
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-187027@lists.php.net to get a copy of this message
Hi, Thursday, May 27, 2004, 11:34:03 AM, you wrote: AP> I've checked the archives and several other sources, but still can't AP> seem to make this work. AP> I have a form with checkboxes to designate records to be deleted from AP> the mysql database. The pertinent form code is: AP> <input type=\"checkbox\" name=\"del[]\" value=\"" . AP> $row['id'] . "\"> AP> The processing code is: if (count($del) >> 0){ AP> for ($i=0;$i<count($del);$i++){ AP> $query = "DELETE FROM ref_events_reg WHERE id = '$del[$i]'"; AP> } AP> } AP> Echoing the query produces: AP> DELETE FROM ref_events_reg WHERE id = A AP> I've also tried the following: AP> $query = "DELETE FROM ref_events_reg WHERE id IN ('" . AP> implode("','", AP> addslashes($del)) . "')"; AP> This one produces a warning: AP> Warning: implode(): Bad arguments. AP> and the following query: AP> DELETE FROM ref_events_reg WHERE id IN ('') AP> Both attempts fail to delete any records even though several records AP> are checked. AP> Where have I gone wrong? AP> Thanks. AP> Albert Padley change it to <input type=\"checkbox\" name=\"del[$row['id']]\" value=\"Y"\"> Then you can do something like foreach($del as $id=>$val){ $query = "DELETE FROM ref_events_reg WHERE id = '$id'"; //do query } -- regards, Tom

« previous php.general (#187027) next »