Re: Delete Multiple Records From Checkboxes

From: Date: Thu, 27 May 2004 05:07:28 +0000
Subject: Re: Delete Multiple Records From Checkboxes
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-187032@lists.php.net to get a copy of this message
On May 26, 2004, at 7:55 PM, Tom Rogers wrote:
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=\"" . $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 ('" . 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 Tom,
When I tried this I received a warning - Warning: Invalid argument supplied for foreach() and, of course, no records were deleted. Albert Padley

« previous php.general (#187032) next »