nominator Posted May 29, 2006 Share Posted May 29, 2006 hi, i am doing a member system. at the admin panel which have a list of user, has a checkbox each at the side. I did a loop to display all user from db and set the checkbox value to the id accordingly[code]$result =mysql_query("Select * from staff");if($myrow = mysql_fetch_array($result));{do{printf(" <tr> <td width=100><span class=text>%s</span></td> <td width=100><input type=checkbox name=check value=%s></td> </tr>",$myrow[name],$myrow[staff_id]); }while($myrow=mysql_fetch_array($result));}[/code]then for my action delete,[code] if($action == 'delete') { $check = $_POST['check']; connect(); mysql_query("Delete from staff where staff_id='$check'"); }[/code]i select a few user to delete, but it only delete one...how can i make it delete whatever i checked. Link to comment https://forums.phpfreaks.com/topic/10691-checkbox-sql/ Share on other sites More sharing options...
samshel Posted May 29, 2006 Share Posted May 29, 2006 [code] $result =mysql_query("Select * from staff");if($myrow = mysql_fetch_array($result));{do{printf(" <tr> <td width=100><span class=text>%s</span></td> <td width=100><input type=checkbox name=check[] value=%s></td> </tr>",$myrow[name],$myrow[staff_id]); }while($myrow=mysql_fetch_array($result));}[/code]and [code]if($action == 'delete') { $check = $_POST['check']; connect(); if(count($check)) { $check_id_list = "(".implode(",",$check).")"; mysql_query("Delete from staff where staff_id in ".$check_id_list); } }[/code] Link to comment https://forums.phpfreaks.com/topic/10691-checkbox-sql/#findComment-39897 Share on other sites More sharing options...
nominator Posted May 29, 2006 Author Share Posted May 29, 2006 [!--quoteo(post=378026:date=May 29 2006, 04:19 AM:name=samshel)--][div class=\'quotetop\']QUOTE(samshel @ May 29 2006, 04:19 AM) [snapback]378026[/snapback][/div][div class=\'quotemain\'][!--quotec--][code] $result =mysql_query("Select * from staff");if($myrow = mysql_fetch_array($result));{do{printf(" <tr> <td width=100><span class=text>%s</span></td> <td width=100><input type=checkbox name=check[] value=%s></td> </tr>",$myrow[name],$myrow[staff_id]); }while($myrow=mysql_fetch_array($result));}[/code]and [code]if($action == 'delete') { $check = $_POST['check']; connect(); if(count($check)) { $check_id_list = "(".implode(",",$check).")"; mysql_query("Delete from staff where staff_id in ".$check_id_list); } }[/code][/quote]not working..Warning: implode(): Bad arguments. in /home/itecollege/domains/itecollege.com/public_html/stcc/manager.php on line 36woops..working le..sorry Link to comment https://forums.phpfreaks.com/topic/10691-checkbox-sql/#findComment-39899 Share on other sites More sharing options...
samshel Posted May 29, 2006 Share Posted May 29, 2006 please try to check if value to $check if passed or not...echo "<pre>";print_r($_POST['check']);echo "</pre>";put this before connect();pl let me know what it displays. Link to comment https://forums.phpfreaks.com/topic/10691-checkbox-sql/#findComment-39902 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.