Deleting Item using Date
Posted: Wed Oct 17, 2007 9:35 pm
Okay, let's see if I can explain this in a way that makes sense. I have my database displaying news fields for a CMS in the following mannor:
in the admin area it is displayed as follows:
What I want to accomplish is, when someone clicks the delete button I want it to delete that entry. The problem I have is connecting the delete button with the SQL item. Please help.
Here is the display for the admin area:
Here is the PHP that processes the form:
Code: Select all
News Heading - Date
Description
-------------------------Code: Select all
Delete Button
News Heading - Date
DescriptionHere is the display for the admin area:
Code: Select all
while($col=mysql_fetch_assoc($result))
{
$col['date'] = date("M,d,Y");
$pull = strtotime($col['pull']);
if ($pull < $time) {
$query = "DELETE FROM news WHERE pull <= $time";}
echo '<div class="newsitem">';
//Delete button settings
echo '<form action="admin.php" method="post">'."\n";
echo '<div class="deleteButton">'."\n";
echo '<input type="submit" value="Delete" name="delete">'."\n";
echo "</div>\n";
//Overall Item Display Settings
echo "<h4>".$col['header']."</h4>";
echo date('m-d-Y',strtotime($col['date']))."\n";
echo "<br><br>\n";
echo $col['description']."<br>\n";
echo "</div>";
}Code: Select all
<?php
//connection settings
$username = "";
$password = "";
$hostname = "localhost";
$select = "SELECT header,date,description,pull FROM news";
$dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL");
$db_table = "news";
print ("Connected to MySQL<br>");
//form variables
$header = $_POST['header'];
$date = $_POST['date'];
$description = $_POST['description'];
$pull = $_POST['pull'];
$sql = "INSERT INTO $db_table(header,date,description,pull) VALUES('$header','$date','$description','$pull')";
$selected = mysql_select_db("biglakebaptist",$dbh) or die("Could not select biglakebaptist");
print ("Selected biglakebaptist<br>");
$result = mysql_query($select) or die("Could not select news");
print ("Selected news table<br>");
if (isset($_REQUEST['delete'])) {
$query = "DELETE FROM news";}
if (isset($_REQUEST['save']))
{
if($result = mysql_query($sql, $dbh)) {
echo "Your info has been added";
}
else {
echo "ERROR: ".mysql_error();
}
}
header("Location: admin_form.php");
mysql_close($dbh);
?>