Error with fetchAll using order by

Asked

Viewed 131 times

0

I’m making a task scheduling system.

I need to show these tasks to the user, created a file called tarefas.php to query the Mysql database:

<?php
    include_once 'conexao-calendario.php';
    include_once 'VerificarLogin.php';
    $usuario = $_SESSION['email'];

    $sql = "SELECT id, titulo, local, data, horario, status FROM eventos WHERE email = '$usuario' ORDER BY data, hora ";
    $select = $pdo->prepare($sql);
    $result = $pdo->query($sql);
    $dados = $result->fetchAll( PDO::FETCH_ASSOC );
    var_dump($dados);
?>

Without the order by appears the correct array, but with it gives the following error:

Fatal error: Uncaught Error: Call to a Member Function fetchAll() on Boolean in C: xampp htdocs Hope tasks.php:9 Stack trace: #0 {main} thrown in C: xampp htdocs Hope tasks.php on line 9

  • You have the field horario but makes ordination by the field hora. Probably if you looked at the PHP error log you would find the problem. Otherwise, there is prepare and has query Then it would be good to review which one to use. It has other problems as well, including lack of string sanitization and mix of upper and lower case in includes.

  • Which is line 9?

  • I checked your script and there was no error, the error may be in another part of the code (we include). Use the prepare method and avoid suffering sql Injection

  • You can show the table structure?

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.