<input type="checkbox" name="opid" id="<?php echo $row['opid'];?>"value="<?php echo $row['opid'];?>"value="<?php echo $_POST['opid'];?>" /> <label for = "<?php echo $row['opid'];?>"></label> <?php $opid= $_POST['opid']; $opids =""; foreach ($_POST['opid'] as $opid ) $opids.=((int)$opid)."," ; $opids=substr($opids,0,-1); $sql="DELETE FROM opentopic WHERE opid IN ($opids)"; $res = mysql_query($sql) or die(mysql_error() ) ; ?>
Hi, I used the above code to delete multiple records with checkboxes. The code is working 100%. All checked information are deleted. THe problem is however that when I open my form I receive the following error message. Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\hello\delchange4.php on line 111 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1.....This is at the line which says foreach ($_POST as $opid ) $opids.=((int)$opid)."," ;.
Once I have selected the checkboxes and pressed delete, the error message is gone. I would like to remove the error message. If anyone can please help. Maybe I am overlooking an obvious mistake. Thank you.