0

I have been getting this error. I have no idea what it is. Any help provided would be awesome.

`require "connect.php";

 $query = "SELECT DVD ID, Name Of the DVD, Quantity FROM DVD";
 $stmt = $dbhandle->prepare( $query );
 $stmt->execute();`

This is where I am getting my error. I researched about the error, they are saying the problem could be with $dbhanle not sure though.

The rest of the code is below.

<?php

session_start();


?>

<!DOCTYPE HTML>

<html>

  <head>

      <title>Shopping Cart</title>
        <link type="text/css" rel="stylesheet" href="basket.css" />

  </head>
  <body>
    <?php
      $action = isset($_GET['action']) ? $_GET['action'] : "";
      $name = isset($_GET['Name Of the DVD']) ? $_GET['Name Of the DVD'] : "";

      if($action=='add'){
       echo "<div>" . $name . " was added to your cart.</div>";
     }

      if($action=='exists'){
       echo "<div>" . $name . " already exists in your cart.</div>";
     }

     require "connect.php";

     $query = "SELECT DVD ID, Name Of the DVD, Quantity FROM DVD";
     $stmt = $dbhandle->prepare( $query );
     $stmt->execute();

     $num = $stmt->rowCount();

     if($num>0){
      echo "<table border='0'>";//start table

        // our table heading
            echo "<tr>";
            echo "<th class='textAlignLeft'>DVD Name</th>";
            echo "<th>Quantity</th>";
            echo "<th>Action</th>";
            echo "</tr>";

        while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
            extract($row);

            //creating new table row per record
            echo "<tr>";
                echo "<td>{$name}</td>";
                echo "<td class='textAlignRight'>{$price}</td>";
                echo "<td class='textAlignCenter'>";
                    echo "<a href='AddToCart.php?id={$id}&name={$name}' class='customButton'>";
                        echo "<img src='images/add-to-cart.png' title='Add To Cart' />";
                    echo "</a>";
                echo "</td>";
            echo "</tr>";
        }

    echo "</table>";
}

// no products in the database
else{
    echo "No products found.";
}

?>
  </body>

</html>

Thank you for your time

2
Contributors
4
Replies
15
Views
3 Years
Discussion Span
Last Post by Mohamed_26
0

I don't think your query is valid: $query = "SELECT DVD ID, Name Of the DVD, Quantity FROM DVD"; looks too plain english.

0

Call to a member function prepare() on a non-object

$query = "SELECT DVD ID, Name Of the DVD, Quantity FROM DVD";
$stmt = $dbhandle->prepare( $query );
$stmt->execute();`

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.