Jump to content

Delete from DB ?


ttmt

Recommended Posts

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.