Record the initial and final date he entered the category and leave the server scheduled to check if it is between the 10-day period, if it did not pass it removes the data.
You can program a crontab script on the server as follows, it will drip your script according to the period you program, and in this script, you do the date check:
Will be executed:
- Once a year:
0 0 1 1 *
.
- Every month:
0 0 1 * *
.
- Once a week:
0 0 * * 0
.
- Once a day:
0 0 * * *
.
- Every hour:
0 * * * *
.
0 0 * * 0 php /path/complete/do/seuscript.php
o seuscript:
<?php
$mysqli = new mysqli("localhost", "root", "senha", "banco");
/* verifica se está conectado */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "DELETE FROM evento
WHERE status =1
AND now() NOT BETWEEN data_inicial AND data_final";
$stmt = $mysqli->prepare($query);
And to record the 10-day period:
$mysqli = new mysqli("localhost", "root", "senha", "banco");
/* verifica se está conectado */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$nome = $_POST['nome'];
$dataInicial = new DateTime();
$dataFinal = new DateTime('+10 days');
$query = "INSERT INTO evento (nome, categoria, status, data_inicial, data_final) VALUES(?,null, 1, ?, ?) ";
$stmt = $mysqli->prepare($query);
$stmt->bind_param("sss", $nome, $dataInicial, $dataFinal);
You’re the bank manager?
– Ricardo
@Ricardo Yes, I am.
– Naldson