CyberShot Posted October 20, 2009 Share Posted October 20, 2009 I have a form that I can type in a name and it displays the name in a list. Below that I have a drop down list that is populated with the same names. What I need is that when you select a name in the drop down list and press the button, it will remove the name from the list. As is right now, I don't get any errrors, but when the page refreshes, the name is still there. Here is what I tried if(isset($_POST['go'])) { $remove = $_POST['drop_name']; $sqlRemove ="DELETE FROM mytable(names) VALUES('$remove')"; } and the drop down list <form method="post"> <select name="drop_name"> <?php foreach ($name as $n): ?> <option><?php echo $n ?></option> <?php endforeach; ?> </select> <input type="submit" name="go" value="remove name" /> </form> my database name is data, table name is mytable and there is two fields.. id, names Quote Link to comment https://forums.phpfreaks.com/topic/178376-solved-help-with-removing-data-from-table/ Share on other sites More sharing options...
lemmin Posted October 20, 2009 Share Posted October 20, 2009 You want to use the WHERE clause with DELETE: DELETE FROM mytable WHERE names = '$remove' Quote Link to comment https://forums.phpfreaks.com/topic/178376-solved-help-with-removing-data-from-table/#findComment-940663 Share on other sites More sharing options...
PFMaBiSmAd Posted October 20, 2009 Share Posted October 20, 2009 This is the DELETE query syntax prototype - DELETE [LOW_PRIORITY] [QUICK] [iGNORE] FROM tbl_name [WHERE where_condition] [ORDER BY ...] [LIMIT row_count] As it applies to what you are doing (removing the unused elements) - DELETE FROM tbl_name WHERE where_condition Quote Link to comment https://forums.phpfreaks.com/topic/178376-solved-help-with-removing-data-from-table/#findComment-940664 Share on other sites More sharing options...
CyberShot Posted October 20, 2009 Author Share Posted October 20, 2009 @PFMaBiSmAd I know answers can be found by reading documentation. I also know that you can write a book on how to read the documentation. I also know that if everyone went to the documentation, there would be no need for this forum. I was going through the documentation. Notice that I did't ask you how to do it, I asked help with code I have been trying @lemmin I tried the code you posted two seconds before receiving your reply, I get the same problem, the page blinks and nothing is removed. Quote Link to comment https://forums.phpfreaks.com/topic/178376-solved-help-with-removing-data-from-table/#findComment-940667 Share on other sites More sharing options...
lemmin Posted October 20, 2009 Share Posted October 20, 2009 Do you have more than one name in each "names" column? That is the right syntax, so if there is a problem, you probably need to give more info. Try turning error reporting on, if you can. Quote Link to comment https://forums.phpfreaks.com/topic/178376-solved-help-with-removing-data-from-table/#findComment-940670 Share on other sites More sharing options...
CyberShot Posted October 20, 2009 Author Share Posted October 20, 2009 I do have more than one name in the names column. it is a first and last name. But I did not make two colums for the names. I did add the error code like this but get nothing $remove = $_POST['drop_name']; DELETE FROM mytable WHERE names = '$remove'; error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/178376-solved-help-with-removing-data-from-table/#findComment-940671 Share on other sites More sharing options...
CyberShot Posted October 20, 2009 Author Share Posted October 20, 2009 well I found one booboo I changed the code to this if(isset($_POST['go'])) { $remove = $_POST['drop_name']; mysql_query("DELETE FROM mytable WHERE names = '$remove'"); error_reporting(E_ALL); } but still no joy Quote Link to comment https://forums.phpfreaks.com/topic/178376-solved-help-with-removing-data-from-table/#findComment-940675 Share on other sites More sharing options...
CyberShot Posted October 21, 2009 Author Share Posted October 21, 2009 got it figured out. thanks for the help guys Quote Link to comment https://forums.phpfreaks.com/topic/178376-solved-help-with-removing-data-from-table/#findComment-940946 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.