Click here to Skip to main content
15,922,427 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Register:
PHP
<?php
    date_default_timezone_set("Africa/Maputo");
    include_once 'config.php';
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Publicacao agendada</title>
</head>
<body bgcolor="#ebebeb">
    <?php 
        if(isset($_POST['accao']) && $_POST['accao'] == 'cadastrar'):
            $filtrar = array(
                'titulo' => FILTER_SANITIZE_STRING,
                'agendado'=>FILTER_SANITIZE_STRING
            );
            $posts = filter_input_array(INPUT_POST, $filtrar);
            if($posts['titulo'] ==''):
                echo 'Preencha o titulo!';

                elseif($posts['agendado'] ==''):
                    $data_agendar = '0000-00-00 00:00:00';
                    $inserir = $pdo->prepare("INSERT INTO `posts` SET `titulo` = ?, agendado = ?, status = ?");
                   if($inserir->execute(array($posts['titulo'], $data_agendar, 1))):
                        echo 'Post publicado com sucesso!';
                endif;

                else:
                   $separar = explode(' ', $posts['agendado']);
                   $sep_dt = explode('/', $separar[0]);
                   $data_agendar = $sep_dt[2]. '-' .$sep_dt[1]. '-' .$sep_dt[0]. '  ' .$separar[1]. ':00';
                
                   $inserir = $pdo->prepare("INSERT INTO `posts` SET `titulo` = ?, agendado = ?, status = ?");
                   if($inserir->execute(array($posts['titulo'], $data_agendar, 0))):
                        echo 'Publicacao agendada com sucesso!';
                   endif;
                endif;
        endif;

    ?>
        <form action="" method="POST" enctype="multipart/form-data">
            <label>
                <span>Titulo</span><br>
                <input type="text" name="titulo" />
            </label><br>
            <label>
                <span>Agendar para:</span><br>
                <input type="text" name="agendado" id="data"/>
            </label><br>
            <input type="hidden" name="accao" value="cadastrar" />
            <input type="submit" value="Cadastrar" />
        </input>

</body>
</html>

Function:
PHP
prepare("SELECT * FROM `posts` WHERE status = '0' AND agendado ! = '0000-00-00 00:00:00'");
        $selecionar_agendados->execute();
        while ($pubAgd = $selecionar_agendados->fetchObject()):

            $data_banco = date('d/m//Y H:i:s', strtotime($pubAgd->agendado));
            if($data_banco <= $dataAgora):
                $actualizar = $pdo->prepare("UPDATE `posts` SET `status` = '1' WHERE id = ?");
                $actualizar->execute(array($pubAgd->id));
            endif;
        endwhile;
    }
    


?>

Index:
PHP
<title>Publicacao agendada
<ul>
    prepare("SELECT * FROM `posts` WHERE `status` = '1'");
        $selecionar_post->execute();
        while($post = $selecionar_post->fetchObject()):
    ?>
    <li>titulo;?></li>
</ul>


What I have tried:

This script is scheduling the tasks however it is not scheduling. can you help me?
Posted
Updated 11-Apr-23 2:01am
v2
Comments
Graeme_Grant 8-Apr-23 19:39pm    
English please.
k5054 8-Apr-23 20:15pm    
Google translate: This script is scheduling some tasks, however, it is not scheduling. Can you help me?

1 solution

You have the following SQL statement that takes 3 parameters:
PHP
$inserir = $pdo->prepare("INSERT INTO `posts` SET `titulo` = ?, agendado = ?, status = ?");

but you have no code to set the values in those statements through any SQL parameters. You are basically inserting nothing into the database because of it.

I don't do PHP, but it seems you're not even declaring the parameter positions correctly, namely using "?" to denote them instead of using named parameters, like ":name", ":cost", ...

See the PHP documentation for PHP: Prepared statements and stored procedures - Manual[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900