Jump to content

Archived

This topic is now archived and is closed to further replies.

nominator

checkbox + sql

Recommended Posts

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.

Share this post


Link to post
Share on other sites
[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]

Share this post


Link to post
Share on other sites
[!--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 36

woops..working le..sorry

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.