Maybe you can run it using ajax
(if that's what you're looking for) like this.
EDIT:
Remember that your now.getHours();
returns a number between 0 and 23, if you want it to be every 24 hours, you must apply the logic as if (hours == 6){}
since, this way you establish that the record is emptied only at a specific time (in this case it is 6, it may well be this time 0). It should also be noted that in the file php id
is the name of the column , in this case we would delete the row with name "record". If what we want is to eliminate the records of the complete table in borrar.php
, where
is over, being as follows delete from $tabla_db1;
In JavaScript.
var now = new Date();
var hours = now.getHours();
if ( hours >= 6 && hours < 21){
$.ajax({
url: "borrar.php",
method: "POST",
async: false,
dataType: "json",
success: function(respuesta) {
var txthora="se vacian registro";
document.write(txthora);
}
});
}
Now, here's the php.
borrar.php
<?php
// Actualizamos en función del nombre que tenemos
$id = 'registro';
include('abre_conexion.php');
$query = "delete from $tabla_db1 where id = '$id'";
$result = mysql_query($query);
include('cierra_conexion.php');
?>