たとえば、データ入力プログラムがあります。このデータを入力してから1日後に自動的にデータを削除します。私はそれをどうやって?
誰かがコードで説明できますか?テーブルのデータの24時間後に、自動的にmysqlテーブルからデータの行を削除するにはどうすればよいですか?
Create.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title></title>
<?php
require_once "db.php";
require_once "function-add.php";
if(isset($_POST['submit'])){
$name_portofolio = $_POST['name_portofolio'];
$info_portofolio = $_POST['info_portofolio'];
$picture_portofolio = $_FILES['picture_portofolio'];
$tipe_file = $_FILES['picture_portofolio'] ['type'];
$tmp_file = $_FILES['picture_portofolio']['tmp_name'];
$ukuran_file = $_FILES['picture_portofolio'] ['size'];
if(!empty(trim($name_portofolio)) && !empty(trim($info_portofolio))) {
if(!empty($_FILES['picture_portofolio']['tmp_name'])){
if($tipe_file === "image/jpeg" || $tipe_file === "image/png" || $tipe_file === "image/jpg"){
if($ukuran_file <= 4000000){
if(create_data($name_portofolio, $info_portofolio, $picture_portofolio)) {
echo "success upload portofolio";
}else{
echo "fail upload portofolio";
}
}else{
echo "max file 1.5 mb";
}
}else{
echo "only.jpeg, .jpg";
}
}else{
echo "try again ";
}
}else{
echo 'try again';
}
}
?>
</head>
<body>
<form action="" method="post" enctype="multipart/form-data">
<table>
<tr>
<td>name portofolio</td>
<td>:</td>
<td><input type="text" name="name_portofolio"></td>
</tr>
<tr>
<td>Info portofolio</td>
<td>:</td>
<td><textarea name="info_portofolio"></textarea></td>
</tr>
<tr>
<td>picture portofolio</td>
<td>:</td>
<td><input type="file" accept="image/*" name="picture_portofolio"></td>
</tr>
<tr>
<td></td>
<td></td>
<td><button type="submit" name="submit">Save</button></td>
</tr>
</table>
</form>
</body>
</html>
機能-add.php
<?php
function create_data($name_portofolio, $info_portofolio, $picture_portofolio){
global $connect;
$name_portofolio = mysqli_real_escape_string($connect, $name_portofolio);
$info_portofolio = mysqli_real_escape_string($connect, $info_portofolio);
$filePath = "picture/".basename($picture_portofolio["name"]);
move_uploaded_file($picture_portofolio["tmp_name"], $filePath);
$query = "INSERT INTO portofolio (name_portofolio, info_portofolio, picture_portofolio) VALUES ('$name_portofolio', '$info_portofolio', '$filePath')";
if(mysqli_query($connect, $query)){
return true;
}else{
return false;
}
}
をdb.php
<?php
$host = "127.0.0.1";
$user = "root";
$password = "";
$db = "wherco";
// create connection
$connect = new mysqli($host, $user, $password, $db);
// check connection
if($connect->connect_error) {
die("connection failed : " . $connect->connect_error);
} else {
// echo "Successfully Connected";
}
?>
感謝。
「cron jobs」を使用 –
cronジョブとは何ですか? –
@wawanD [cronジョブとは何ですか](http://support.hostgator.com/articles/cpanel/what-are-cron-jobs) – hungrykoala