M
M
millwright2015-12-07 23:53:51
PHP
millwright, 2015-12-07 23:53:51

How to get the result of a prepared query?

You need to get the result of the request by the received ID. I'm trying to do it like this:

try {
        $sql = 'SELECT * FROM tricks WHERE id = :id';
        $s = $pdo->prepare($sql);
        $s->bindValue(':id', $_POST['id']);
        $s->execute();
    } catch (Exception $ex) {
        include $_SERVER['DOCUMENT_ROOT'] . '/includes/error.html.php';
        exit();
    }

    $row = $s->fetch();
    
    $name = $row['tname'];
    $description = $row['tdescription'];
    
    include 'test.php';

I am getting empty values. You can do without a prepared request in this case, but I want to know what's wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
svd71, 2015-12-07
@svd71

The problem is that the result is an array of strings. So the index must be of type $row[0]['tname'].
The print-r($row) function will print everything to your browser for debugging.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question