ttmt Posted January 22, 2009 Share Posted January 22, 2009 Hi all I have a simple script that adds a new row to a DB, now I'm stuck on how to delete from the DB The code is two simple forms one that adds a new row and one form that is a dropdown menu which shows all the rows in the DB. I want to be able to select from the drop down menu and delete it. confirm_query - function that confirms query worked. mysql_prep - function that prepears variable for input to DB <?php require_once("includes/connection.php"); require_once("includes/functions.php"); include("includes/header.php"); ?> <?php if(isset($_POST['submit_1'])){ $new_section = trim(mysql_prep($_POST['section'])); $query = "INSERT INTO keywords (words) VALUES ('{$new_section}')"; $result = mysql_query($query); confirm_query($result); } ?> <?php if(isset($_POST['submit_2'])){ //delete Section ? } ?> <?php $query = "SELECT key_id, words FROM keywords"; $result = mysql_query($query); confirm_query($result); $delete_options =""; while($row = mysql_fetch_array($result)){ $delete_options .= "<option value=\"$row[0]\">{$row[1]}</option>"; } ?> <body> <div id="con"> <form name="new_section" action="preupTest.php" method="post"> <p> New Section:<br /> <textarea name="section" cols="30" rows="1"></textarea><br /> <input type="submit" name="submit_1" value="Add Section" /> </p> </form> <br/> <form name="delete_section" action="preupTest.php" method="post"> Delete Section: <select name="del_sec"> <?php echo $delete_options; ?> </select> <input type="submit" name="submit_2" value="Delete Section" /> </form> </div> </body> </html> Quote Link to comment Share on other sites More sharing options...
Philip Posted January 22, 2009 Share Posted January 22, 2009 Take a look at: http://www.tizag.com/mysqlTutorial/mysqldelete.php Syntax is "DELETE FROM `tablename` WHERE `column`='value' " Quote Link to comment Share on other sites More sharing options...
ttmt Posted January 22, 2009 Author Share Posted January 22, 2009 I'll take a look at your link The sql syntax isn't the problem it's finding the column value that I'm stuck on. It's getting an id from the drop down menu. Quote Link to comment Share on other sites More sharing options...
phparray Posted January 22, 2009 Share Posted January 22, 2009 Looks like your id will be in $_POST['del_sec'] DELETE FROM words WHERE key_id = $_POST['del_sec'] 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.