buzzkip Posted September 2, 2010 Share Posted September 2, 2010 Hi all, Please could someone guide me as to how I would create a simple php page, that has a dropdown list populated by a database table - and then a submit button. When I select an option in the dropdown list and then click submit, it deletes the row from the database table. Would be very much appreciative of some help Quote Link to comment Share on other sites More sharing options...
laanes Posted September 2, 2010 Share Posted September 2, 2010 Hi all, Please could someone guide me as to how I would create a simple php page, that has a dropdown list populated by a database table - and then a submit button. When I select an option in the dropdown list and then click submit, it deletes the row from the database table. Would be very much appreciative of some help Post your code here for people to look at so they can help you. Quote Link to comment Share on other sites More sharing options...
buzzkip Posted September 2, 2010 Author Share Posted September 2, 2010 table: inplace columns: field, value, stock The drop down displays the value columns perfectly, but when I hit the submit button... nothing happens. <?php //create_topic.php include 'connect.php'; include 'header.php'; echo '<h2>Delete an item in the database</h2>'; if($_SESSION['signed_in'] == false) { echo 'Sorry, you have to be signed in.'; } else { if($_SERVER['REQUEST_METHOD'] != 'POST') { $sql = "SELECT field, value, stock FROM inplace"; $result = mysql_query($sql); if(!$result) { echo 'Error while selecting from database. Please try again later.'; } else { if(mysql_num_rows($result) == 0) { if($_SESSION['user_level'] == 1) { echo 'You have not created any items yet.'; } else { echo 'Before you can post an item, you must wait for an admin to create some locations.'; } } else { echo '<form method="post" action=""> Item: <select name="field">'; while($row = mysql_fetch_assoc($result)) { echo '<option value="' . $row['field'] . '">' . $row['value'] . '</option>'; } echo '</select><input type="submit" value="Delete item" /></form>'; } } } else { $query = "BEGIN WORK;"; $result = mysql_query($query); if(!$result) { echo 'An error occured while deleting your item. Please try again later.'; } else { $sql = "DELETE FROM inplace WHERE value = ' " . $_POST['value'] . " ' "; $result = mysql_query($sql); if(!$result) { echo 'An error occured while deleting your data. Please try again later.<br /><br />' . mysql_error(); $sql = "ROLLBACK;"; $result = mysql_query($sql); } else { $topicid = mysql_insert_id(); $sql = "DELETE FROM inplace WHERE value = ' " . $_POST['value'] . " ' "; $result = mysql_query($sql); if(!$result) { echo 'An error occured while deleting your item. Please try again later.<br /><br />' . mysql_error(); $sql = "ROLLBACK;"; $result = mysql_query($sql); } else { $sql = "COMMIT;"; $result = mysql_query($sql); echo 'You have succesfully deleted your new item.'; } } } } } include 'footer.php'; ?> Quote Link to comment Share on other sites More sharing options...
fenway Posted September 7, 2010 Share Posted September 7, 2010 I'm sure something happens -- if you get a blank page, that's something else. Define "nothing". Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.