PHP AUTO Delete / Expire Date

CREATE TABLE IF NOT EXISTS `file` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `description` varchar(100) NOT NULL,
  `content` varchar(1000) NOT NULL,
  `expiry` varchar(15) NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2 ;


INSERT INTO `file` (`id`, `description`, `content`, `expiry`) VALUES
(1, 'blogG-ngelantur', '
Collection, you too I ', '2012/07/15');

index.php
<html>
<head>
<title>bloG-ngelantur</title>
</head>
<body>
<a href="index.php">Add New</a> | <a href="archives.php">Archives</a>
<form method="post" action="save.php">
  <table width="444" border="0" align="left" cellpadding="0" cellspacing="0">
    <tr>
      <td valign="top"><div align="right">Description:</div></td>
      <td><label>
        <input name="description" type="text" id="desc" />
      </label></td>
    </tr>
    <tr>
      <td valign="top"><div align="right">Content:</div></td>
      <td><label>
        <div align="left">
          <textarea name="content" cols="30" rows="5" id="content"></textarea>
          </div>
      </label></td>
    </tr>
    <tr>
      <td valign="top"><div align="right">Expire Of Days </div></td>
      <td>
        <select name="numdays" id="numdays">
        <option value="" disabled selected>- Select Day -</option>
        <? 
        $i = 0;
        do { $i++;
        echo"<option value='$i' >$i Day</option>";
        } while ($i <=10);?>
        </select></td>
    </tr>
    <tr>
      <td><div align="right"></div></td>
      <td><label>
        <input type="submit" name="Submit" value="Submit" />
      </label></td>
    </tr>
  </table>
</form>
</body>
</html>


save.php
<?php

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("file", $con);
$numdays=$_POST['numdays'];
$content=$_POST['content'];
$description=$_POST['description'];
$tomorrow = mktime(0,0,0,date("m"),date("d")+$numdays,date("Y"));
$dats=date("Y/m/d", $tomorrow);
mysql_query("INSERT INTO file(description, content, expiry)VALUES('$description', '$content', '$dats')");
header("location: index.php");
mysql_close($con);

?>



archives.php
<?php

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("file", $con);
$curdate=date("Y/m/d");
mysql_query("DELETE FROM file WHERE expiry='$curdate'");
mysql_close($con);
?>
<title>bloG-ngelantur</title> 
<a href="index.php">Add New</a> | <a href="archives.php">Archives</a>
<?php
$con = mysql_connect("localhost","root","");
if (!$con){
  die('Could not connect: ' . mysql_error());
   }
  mysql_select_db("file", $con);


$result = mysql_query("SELECT * FROM file");

echo "<table width='100%' border='1' align='center' cellpadding='0' cellspacing='0'>
<tr>
<th>Description</th>
<th>Content</th>
<th>Expire date</th>
</tr>";

while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td><div align='center'>" . $row['description'] . "</td>";
  echo "<td><div align='center'>" . $row['content'] . "</td>";
  echo "<td><div align='center'>" . $row['expiry'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

mysql_close($con);
?> 

1 komentar:

Anonim mengatakan...

Thanhs.....