Jump to content

Delete Function In Php From Checkbox


then90

Recommended Posts

I have doubt on how to include two fields(Productcode,Effectivedate) that is to be considered on deletion. Following is the code,

 

Following is the code for delete function,

 

if(isset($_POST['Delete']))
{


$checkbox = $_POST['checkbox']; //from name="checkbox[]"
$countCheck = count($_POST['checkbox']);
for($i=0;$i<$countCheck;$i++)
{
$prodidd = $checkbox[$i];
$prod1 = $checkbox[$i];
///$prodid= $_POST['checkbox'];
$sql = "DELETE FROM `oemanucfacturemapping` WHERE Productcode ='".$prodidd."' and Effectivedate = '".$prod1."'";
$result = mysql_query($sql);
}

if($result){
?>
           <script type="text/javascript">
alert("Deleted  Successfully!!");document.location='oemanufacturermap.php';
</script>
   <?

}
}

 

 

The checkbox value is taken from the following code,

 

 

 <table align="center" class="sortable" bgcolor="#FF0000" border="1" width="900px">

    <td>#</td><strong><td>OEManufacturer Name</td></strong><td>Product Code</td><td>Manufacturer Warranty</td><td>Sales Warranty</td><td>Effective Date</td><td>KMRun</td><td>####</td>
<?php
     // This while will loop through all of the records as long as there is another record left. 
     while( $record = mysql_fetch_array($query))
   { // Basically as long as $record isn't false, we'll keep looping.
     // You'll see below here the short hand for echoing php strings.
     // <?=$record[key] - will display the value for that array.
   ?>

    <tr>
    <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $record['Productcode'],$record['Effectivedate'];?>"></td>
   <td  bgcolor="#FFFFFF">
       <?=$record['OEManufacturename']?>
   </td>
    <td  bgcolor="#FFFFFF"  align="left" valign="top">
       <?=$record['Productcode']?>
   </td>
    <td  bgcolor="#FFFFFF"  align="left" valign="top">
       <?=$record['ManufacturingWarranty']?>
   </td>
    <td  bgcolor="#FFFFFF"  align="left" valign="top">
       <?=$record['Saleswarranty']?>
   </td>
   <td  bgcolor="#FFFFFF"  align="left" valign="top">
       <?=$record['Effectivedate']?>
   </td>
   <td  bgcolor="#FFFFFF"  align="left" valign="top">
       <?=$record['KMRun']?>
   </td>
   <td bgcolor="#FFFFFF" align="left" valign="top"> <a name="edit" href="oemanufacturermap.php?Productcode=<?=$record['Productcode']?>&Effectivedate=<?=$record['Effectivedate'];?>">Edit</a></td>

 <?php
     }
 ?>
</table>

 

 

Help pls, How can i do this?

Link to comment
https://forums.phpfreaks.com/topic/269119-delete-function-in-php-from-checkbox/
Share on other sites

if the product codes are numeric

<?php
$products = join(',', array_filter(array_map('intval', $_POST['checkbox'])));
$sql = "DELETE FROM `oemanucfacturemapping` WHERE Productcode IN ($products) AND Effectivedate = '$prod1'";
?>

 

if they are not numeric, then

<?php
$products = join("','", array_filter(array_map('mysql_real_escape_string', $_POST['checkbox'])));
$sql = "DELETE FROM `oemanucfacturemapping` WHERE Productcode IN ('$products') AND Effectivedate = '$prod1'";
?>

Archived

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

×
×
  • Create New...

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.