grahamb314 Posted September 14, 2008 Share Posted September 14, 2008 Hi All I have a page which selects data from a database correctly and it displays it all fine within the dropdown box. And then I want to delete what I select from the dropdown box The problem is when I press delete, the selected item from the dropdown box does not POST to the php page (Which is perfectly designed to delete the POST variable) I want 'select' to be what i select and then 'select' to be the post variable in the 2nd page Any help would be fantastic! index page: <html> <head> <title></title> </head> <body> <div align="center"></div> <div align="center"><img src="Purple_Logo.jpg" width="300" height="113"></div> <form action="mysql_delete_show.php" method="POST"><select name="select"> <?php require_once 'mysql_connect.php'; // this connects to the databse correctly // $DJshows = mysqli_query($mysqli, "SELECT * FROM shows"); while ($show = mysqli_fetch_assoc($DJshows)) { echo "<option value=\"{$show['show']}\">{$show['show']}</option>"; } ?> </select> <input type="submit" value="Delete"> </p> </form> </form> <input name="BUTTON3" type="BUTTON" onClick="javascript:history.go(-1)" value="Back"> </body> </html> and here is the mysql_delete_show.php code <?php require_once 'mysql_connect.php'; $query = "DELETE FROM `shows` WHERE `shows`.`show` ='{$_POST["option"]}';"; mysqli_query($mysqli, $query) or die("Query:{$query} <br>Error:".mysqli_error($mysqli)); echo "<p>If there are no errors, the show <b> ".$_POST["option"]." </b> has been deleted from the database!"; ?> Link to comment https://forums.phpfreaks.com/topic/124174-solved-post-from-dropdown-box/ Share on other sites More sharing options...
BlueSkyIS Posted September 14, 2008 Share Posted September 14, 2008 you name your 'select' select, but then you check $_POST["option"] instead of $_POST["select"]. select is the name of the form element you want to check, not option. $query = "DELETE FROM `shows` WHERE `shows`.`show` ='{$_POST["select"]}';"; p.s. i wouldn't name any form element select, especially not a 'select' form element. too confusing. i'd name it something more like 'toDelete' or something: <select name="toDelete"> then $toDelete = mysql_real_escape_string($_POST['toDelete']); $query = "DELETE FROM `shows` WHERE `show` = '$toDelete';"; Link to comment https://forums.phpfreaks.com/topic/124174-solved-post-from-dropdown-box/#findComment-641106 Share on other sites More sharing options...
grahamb314 Posted September 14, 2008 Author Share Posted September 14, 2008 The People on this forum are great! Thanks for that BlueSkyIS (I spent an hour on this one and its always something silly!!) Thanks again Link to comment https://forums.phpfreaks.com/topic/124174-solved-post-from-dropdown-box/#findComment-641114 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.