I need PHP code for date range deletion for date and date_time columns in MYSQL DB.
I have a php form which has two select option drop downs. These drop are populated by a date_time column in MySQL and posted for deletion using $_POST as follows:
I want to know what should I do in the delete SQL query to able to delete the rows requested by the form? Thank you.
I have a php form which has two select option drop downs. These drop are populated by a date_time column in MySQL and posted for deletion using $_POST as follows:
Code:
<h4>Delete News </h4>
<?php
include ('conn_db.php');
if ($_POST['submit'])
{
$start_date = $_POST['start_date'];
$end_date = $_POST['end_date'];
echo $start_date;
echo $end_date;
@mysql_query ("delete from dow_news where date_format(pub_dt, '%b, %d %Y %W') like between '%$start_date%' and '%$end_date%'");
echo "<script> alert ('News Deleted.')<//script>";
echo '<meta http-equiv="refresh" content="0;url=delete_news.php" />';
}
?>
<form name="form1" action="delete_news.php" method="POST">
<?php
$query = "select distinct date_format(pub_dt, '%b, %d %Y %W') pub_dt1 from dow_news";
$result = @mysql_query ($query);
echo "News Deletion Start Date ";
echo "<select name= \"start_date\">";
while ($row_start = mysql_fetch_array ($result, MYSQL_ASSOC))
if ( $row_start['pub_dt1'] == $start_date)
echo "<option selected value=\"{$row_start['pub_dt1']}\">{$row_start['pub_dt1']}</option>\n";
else
echo "<option value=\"{$row_start['pub_dt1']}\">{$row_start['pub_dt1']}</option>\n";
echo "</select>";
echo "<br />";
echo "<br />";
$result = @mysql_query ($query);
echo "News Deletion End Date ";
echo "<select name= \"end_date\">";
while ($row_end = mysql_fetch_array ($result, MYSQL_ASSOC))
if ( $row_end['pub_dt1'] == $end_date)
echo "<option selected value=\"{$row_end['pub_dt1']}\">{$row_end['pub_dt1']}</option>\n";
else
echo "<option value=\"{$row_end['pub_dt1']}\">{$row_end['pub_dt1']}</option>\n";
echo "</select>";
?>
<br />
<br />
<input type="submit" name="submit" value="Delete">
</form>
I want to know what should I do in the delete SQL query to able to delete the rows requested by the form? Thank you.