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?

Edited by KevinM1
Added code tags
Link to comment
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'";
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.