phprockers-logo

How to delete checked checkbox rows in php?

<?php
if($_REQUEST['btndelete'] != '')
{
    if(!empty($_REQUEST['checkboxstatus'])) {
        $checked_values = $_REQUEST['checkboxstatus'];
        foreach($checked_values as $val) {
            $sqldel = "delete from subscribe where id = '$val'";
            $resdel = mysql_query($sqldel);
            if($resdel)
                $error_log = 1;
            else
                $error_log = 2;
        }
    }
}

$openingcountry = $_REQUEST['openingcountry'];
if($_REQUEST['status'] != '') {
    $status = $_REQUEST['status'];
}
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<form name="frmcountry" method="post" action="">
<table align="center" cellpadding="0" cellspacing="0" border="0" width="100%">
    <tr>
        <td>
        <input type="submit" name="btndelete" value="DELETE" class="openlistdelete" onClick="javascript: return confirm('Are you sure you want to delete!')" />
        <div style="color:#FF0000;">
        <?php
                if($error_log == 2)
                    echo "Selected email id is not deleted";
                if($error_log == 1)
                    echo "Deleted successfully";

            ?>
        </div>
               </td>
        </tr>
    <tr>
            <td class="openingtitletxt">S.No. </td>
            <td class="openingtitletxt">Email </td>

        <td class="openingtitletxt">Country </td>
            <td class="openingtitletxt">Statu </td>
        <td class="openingtitletxt">Edit Status </td>
        </tr>
        <?
    $rest = '';
                           
    if($openingcountry != "") {
        $rest .= "where country = '$openingcountry'";
    }
    if($status!='') {   
        if($openingcountry != "")
        $rest.= " and status = '$status'";
        else
        $rest.= "where status = '$status'";
    }                                       
        $sqlselopenings = "select * from subscribe ".$rest ."ORDER BY id desc";
    $resselopenings = mysql_query($sqlselopenings);
    if($resselopenings) {
        $numrowsopenings = mysql_num_rows($resselopenings);
    }   
                           
    if($numrowsopenings > 0) {
        $i = 1;
        while($rowselopenings = mysql_fetch_array($resselopenings)) {
                ?>
                <tr>
                        <td class="openingtitledetails"> <? echo $i;?></td>
                        <td class="openingtitledetails"><? echo $rowselopenings['email'];?></td>
            <td class="openingtitledetails">
                <?if($rowselopenings['country'] == 'uk')
                    echo $rowselopenings['country'] = 'UK';
                    else if($rowselopenings['country'] == 'us')
                    echo $rowselopenings['country'] = 'US';
                    else
                    echo $rowselopenings['country'] = ucfirst($rowselopenings['country']);?>
                        </td>
                        <td class="openingtitledetails">
                        <?
                if($rowselopenings['status'] == 1) {
                    echo 'Active';
                } else {   
                    echo 'Inactive';
                }
            ?>                               
            </td>
            <td class="openingtitledetails">
            <input type="checkbox" name="checkboxstatus[<?php echo $i; ?>]" id="checkboxstatus-<?php echo $rowselopenings['id']; ?>" value="<?php echo $rowselopenings['id']; ?>"  />
            </td>
        </tr>
                <? $i++;
        }
    } else { ?>
        <tr>
            <td colspan="5" align="center" class="errortxt"> No Records Found! </td>
        </tr>   
        <? } ?>
</table>
</form>  
</body>
</html>

0 comments:

Post a Comment