mvasco
mvasco

Reputation: 5101

Fatal error on PHP prepare()

This is part of my PHP code, which is showing the error:

Fatal error: Call to a member function prepare() on a non-object in /../EditAdminRestaurantes.php on line 61

Here the code:

         <?php

        $id=$_GET['id'];
line 61-> $result = $db->prepare("SELECT * FROM tbrestaurantes WHERE id_restaurante= :userid");
        $result->bindParam(':userid', $id);
        $result->execute();
        for($i=0; $row = $result->fetch(); $i++){
    ?>

I have checked the table name and it is ok: tbrestaurantes, the field id_restaurante is also ok.

Any help is welcome.

Upvotes: 0

Views: 47

Answers (1)

Fluffeh
Fluffeh

Reputation: 33512

Providing an answer based on the commentary leading to solving the problem:

 <?php

    $id=$_GET['id'];
    $result = $dbh->prepare("SELECT * FROM tbrestaurantes WHERE id_restaurante= :userid");
    $result->bindParam(':userid', $id);
    $result->execute();
    for($i=0; $row = $result->fetch(); $i++)
    {
        // etc etc
?>

The database object $db was incorrectly being called when it was actually supposed to be $dbh.

Upvotes: 1

Related Questions