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
https://forums.phpfreaks.com/topic/141971-delete-from-db/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.