Cory94bailly Posted June 19, 2008 Share Posted June 19, 2008 <?php require('config.php'); if ( isset($_POST['selected']) && is_array($_POST['selected']) ) { $selected = implode(",", $_POST['selected']); mysql_query("DELETE FROM recent WHERE id IN ($selected)"); echo "<meta http-equiv='refresh' content='1' />Selected recent deleted!"; } elseif(isset($_POST['deleteall'])) { mysql_query('TRUNCATE TABLE recent'); echo "<meta http-equiv='refresh' content='1' />All recent deleted!"; } else { ?> <head> <title>Add/Delete Recently Made</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <br /> <div id="menu"> <? include('menu.html'); ?> </div> <div id="content"> <form action="upload.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> <br /> <table border="1" cellpadding="5"> <tr><td> </td><td>ID</td><td><center>Name</center></td> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <?php $query = "SELECT * FROM recent"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<tr>"; echo "<td>"; echo "<input type='checkbox' name='selected[]' value='$row[id]' />"; echo "</td>"; echo "<td>"; echo $row['ID']; echo "</td>"; echo "<td>"; echo $row['name']; echo "</td>"; echo "</tr>"; } ?> </table> <br> <input type="submit" name="deleteselected" value="Delete Selected"> <input type="submit" name="deleteall" value="Delete All"> </form> </div> </body> </html> <? } ?> ^^My code. Now the problem is that if I select a checkbox, it doesn't delete it... But if I press delete all, it deletes all... I have another script much like this one and it works but not here.. Link to comment https://forums.phpfreaks.com/topic/111007-delete-with-checkbox-all-done-just-1-problem/ Share on other sites More sharing options...
lemmin Posted June 19, 2008 Share Posted June 19, 2008 First thing you should do is add or die(mysql_error()); to the end of your query so you can see if there is an error there. I know that if the 'id' field isn't formatted as a number, that query will give an error. Link to comment https://forums.phpfreaks.com/topic/111007-delete-with-checkbox-all-done-just-1-problem/#findComment-569604 Share on other sites More sharing options...
phpzone Posted June 19, 2008 Share Posted June 19, 2008 echo "<input type='checkbox' name='selected[]' value='$row[id]' />"; Yes I think that line above should be $row['ID'] judging by the rest of the code. Link to comment https://forums.phpfreaks.com/topic/111007-delete-with-checkbox-all-done-just-1-problem/#findComment-569608 Share on other sites More sharing options...
Cory94bailly Posted June 19, 2008 Author Share Posted June 19, 2008 First thing you should do is add or die(mysql_error()); to the end of your query so you can see if there is an error there. I know that if the 'id' field isn't formatted as a number, that query will give an error. 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 Link to comment https://forums.phpfreaks.com/topic/111007-delete-with-checkbox-all-done-just-1-problem/#findComment-569662 Share on other sites More sharing options...
Stephen Posted June 19, 2008 Share Posted June 19, 2008 Line1 doesn't even have a mysql query. You put "or die(mysql_error());" after mysql_query(); So it would look like: mysql_query() or die(mysql_error()); Link to comment https://forums.phpfreaks.com/topic/111007-delete-with-checkbox-all-done-just-1-problem/#findComment-569667 Share on other sites More sharing options...
Cory94bailly Posted June 19, 2008 Author Share Posted June 19, 2008 <?php require('config.php'); if ( isset($_POST['selected']) && is_array($_POST['selected']) ) { $selected = implode(",", $_POST['selected']); mysql_query("DELETE FROM recent WHERE id IN ($selected)") or die(mysql_error()); echo "<meta http-equiv='refresh' content='1' />Selected recent deleted!"; } elseif(isset($_POST['deleteall'])) { mysql_query('TRUNCATE TABLE recent') or die(mysql_error()); echo "<meta http-equiv='refresh' content='1' />All recent deleted!"; } else { ?> <head> <title>Add/Delete Recently Made</title> <link href="style.css" rel="stylesheet" type="text/css" /> </head> <body> <br /> <div id="menu"> <? include('menu.html'); ?> </div> <div id="content"> <form action="upload.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> </form> <br /> <table border="1" cellpadding="5"> <tr><td> </td><td>ID</td><td><center>Name</center></td> <form action="<?php echo $_SERVER['PHP_SELF'] ?>" method="post"> <?php $query = "SELECT * FROM recent"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo "<tr>"; echo "<td>"; echo "<input type='checkbox' name='selected[]' value='$row[id]' />"; echo "</td>"; echo "<td>"; echo $row['ID']; echo "</td>"; echo "<td>"; echo $row['name']; echo "</td>"; echo "</tr>"; } ?> </table> <br> <input type="submit" name="deleteselected" value="Delete Selected"> <input type="submit" name="deleteall" value="Delete All"> </form> </div> </body> </html> <? } ?> Link to comment https://forums.phpfreaks.com/topic/111007-delete-with-checkbox-all-done-just-1-problem/#findComment-569668 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.