then90 Posted October 5, 2012 Share Posted October 5, 2012 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 More sharing options...
White_Lily Posted October 5, 2012 Share Posted October 5, 2012 Re-post the code with the coding tags please. Link to comment https://forums.phpfreaks.com/topic/269119-delete-function-in-php-from-checkbox/#findComment-1382874 Share on other sites More sharing options...
KevinM1 Posted October 5, 2012 Share Posted October 5, 2012 Re-post the code with the coding tags please. Already edited. That's what we moderators are for. Link to comment https://forums.phpfreaks.com/topic/269119-delete-function-in-php-from-checkbox/#findComment-1382875 Share on other sites More sharing options...
White_Lily Posted October 5, 2012 Share Posted October 5, 2012 Thats scary - knowing mods can just randomly edit our original posts lol Link to comment https://forums.phpfreaks.com/topic/269119-delete-function-in-php-from-checkbox/#findComment-1382881 Share on other sites More sharing options...
White_Lily Posted October 5, 2012 Share Posted October 5, 2012 Ive already seen the biggest problem... Your posting values without a form lol Link to comment https://forums.phpfreaks.com/topic/269119-delete-function-in-php-from-checkbox/#findComment-1382884 Share on other sites More sharing options...
Barand Posted October 5, 2012 Share Posted October 5, 2012 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 https://forums.phpfreaks.com/topic/269119-delete-function-in-php-from-checkbox/#findComment-1383067 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.