In this tutorial we will show you how to create a simple application called
Automatic Delete Product From Database Based On Expiry Date. This simple application is created to delete an existing product based on the products expiry date. This application is made using PHP, MySQL and Bootstrap UI design to make more responsive to the users.
Sample Code
Tab-Archieve.php - This script is for viewing of product list.
<!DOCTYPE html>
<html>
<head>
<title>Automated Delete Product Date Expiry</title>
</head>
<body>
<div class="tab-pane fade in active" id="archieve">
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="example">
<thead>
<?php
if (!$con)
{
}
mysql_query("DELETE FROM prod_list WHERE expiry='$curdate'");
?>
<?php
if (!$con)
{
}
echo "<div align='center'>Note: the data will automatically deleted when it reach the expiry date"."</div><br>";
echo "
<tr>
<th>Product</th>
<th>Description</th>
<th>Expiry date</th>
</tr>";
{
echo "<tr>";
echo "<td><div align='center'>" . $row['product'] . "</td>";
echo "<td><div align='center'>" . $row['description'] . "</td>";
echo "<td><div align='center'>" . $row['expiry'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
</tbody>
</table>
</div>
</body>
</html>
Tab-Add.php - And this is for creating a new products to be added in the list.
<!DOCTYPE html>
<html>
<head>
<title
>Automated Delete Product
Date Expiry
</title
>
</head>
<style>
.containers{
margin-right:345px;
margin-left:320px;
}
</style>
<body>
<div class="tab-pane fade"id="add">
<div class="containers">
<p align="center" style="color:#000">Fill Up All The Details Below!</p>
<form class="form-horizontal" method="POST" action="save.php">
<div class="form-group">
<label class="control-label col-sm-2" for="product">Product:</label>
<div class="span4">
<input type="text" name="product" class="form-control" id="product" placeholder="Product" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="description">Description:</label>
<div class="span4">
<input type="text" name="description" class="form-control" id="description" placeholder="Description" required>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="numdays">Number of Days:</label>
<div class="span4">
<input type="text" name="numdays" class="form-control" id="numdays" placeholder="Number of Days" required>
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-10">
<button type="submit" name="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
</div>
</body>
</html>
Save.php - This is for the query from the tab_add.php to create and save it directly to the database and set by the date expiry.
<?php
if (!$con)
{
}
$numdays=$_POST['numdays'];
$product=$_POST['product'];
$description=$_POST['description'];
$dats=date("Y/m/d", $tomorrow);
mysql_query("INSERT INTO prod_list(product, description, expiry)VALUES('$product', '$description', '$dats')");
header("location: index.php");
?>
Hope that you learn in this tutorial. And for more updates and programming tutorials don't hesitate to ask and we will answer your questions and suggestions. Don't forget to
LIKE &
SHARE this website.