1
I’m making a system where the user can schedule posts, IE, if he enters the date and time, the post will be released when the current date is equal to the entered, until then the logic is simple but I’m having problems to apply it to a function.
I watched a video classroom but it is very old and uses parameters that I could not use so I adapted the code but still does not work.
The function is like this:
function publicarAgendado(){
date_default_timezone_set('America/Sao_Paulo');
$dataAgora = date('d-m-Y H:i:s');
$selecionar_agendados = @mysqli_query("SELECT * from postagens where status = 0");
while ($PubAgd = @mysqli_fetch_array($selecionar_agendados)) {
$aiai = $PubAgd['id'];
setlocale(LC_TIME,'pt_BR','pt_BR.utf-8','portuguese');
date_default_timezone_set('America/Sao_Paulo');
$data_banco = date('d/m/Y H:i:s', strtotime($PubAgd['agendado']));
if ($data_banco <= $dataAgora) {
$up = mysqli_query("UPDATE postagens SET status=1 where id= $aiai");
}
}
}
In the database the field of that date is as datetime and in the HTML is in an input with the type datetime-local. Please help me urgently because I have to deliver a preview of this system tomorrow.
Welcome Julia, know that it is always good to mark an answer as you accept, in case she solves your problem. See how in https://i.stack.Imgur.com/evLUR.png and why in https://pt.meta.stackoverflow.com/questions/1078/como-e-por-que-aceitar-uma-resposta/1079#1079
– user60252