saradrungta Posted December 31, 2008 Share Posted December 31, 2008 can some 1 help in finding error in below code its not deleting data from DB <?php // Connect to server and select databse. mysql_connect("localhost","root","")or die("cannot connect"); mysql_select_db("sarad")or die("cannot select DB"); $sql="SELECT * FROM studentrec"; $result=mysql_query($sql); $count=mysql_num_rows($result); ?> <table width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <td><form name="form1" method="post" action="adelete.php"> <table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"> <tr> <td bgcolor="#FFFFFF"> </td> <td colspan="4" bgcolor="#FFFFFF"><strong>Delete multiple rows in mysql</strong> </td> </tr> <tr> <td align="center" bgcolor="#FFFFFF">#</td> <td align="center" bgcolor="#FFFFFF"><strong>Id</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>Age</strong></td> <td align="center" bgcolor="#FFFFFF"><strong>City</strong></td> </tr> <?php $count=1; while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name= "checkbox[]; ?>" type="checkbox" id="checkbox[]" value="<? echo $rows['UID']; ?>"></td> <td bgcolor="#FFFFFF"><?php echo $rows['UID']; ?></td> <td bgcolor="#FFFFFF"><?php echo $rows['Name']; ?></td> <td bgcolor="#FFFFFF"><?php echo $rows['age']; ?></td> <td bgcolor="#FFFFFF"><?php echo $rows['city']; ?></td> </tr> <?php $count++; } ?> <tr> <td colspan="5" align="center" bgcolor="#FFFFFF"><input name="delete" type="submit" id="delete" value="Delete"></td> </tr> <?php // Check if delete button active, start this if($_POST['delete']){ for($i=0;$i<$count;$i++){ $del_id = $_POST['checkbox[$i]']; $sql = "DELETE FROM studentrec WHERE id='$del_id'"; $result = mysql_query($sql); } // if successful redirect to delete_multiple.php if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=xyz.php\">"; } } mysql_close(); ?> </table> </form> </td> </tr> </table> Link to comment https://forums.phpfreaks.com/topic/139031-solved-multiple-delete/ Share on other sites More sharing options...
gwydionwaters Posted December 31, 2008 Share Posted December 31, 2008 maybe where you have $sql = "DELETE FROM studentrec WHERE id='$del_id'"; should it be $sql = "DELETE * FROM studentrec WHERE id='$del_id'"; Link to comment https://forums.phpfreaks.com/topic/139031-solved-multiple-delete/#findComment-727195 Share on other sites More sharing options...
saradrungta Posted January 1, 2009 Author Share Posted January 1, 2009 still facing same problem Link to comment https://forums.phpfreaks.com/topic/139031-solved-multiple-delete/#findComment-727355 Share on other sites More sharing options...
darkfreaks Posted January 1, 2009 Share Posted January 1, 2009 <?php $result=mysql_query($sql) or die(mysql_error()); // should error if MSQL is wrong ?> Link to comment https://forums.phpfreaks.com/topic/139031-solved-multiple-delete/#findComment-727358 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.