473,320 Members | 2,003 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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

I have been getting this error, I have no idea what that is.

Expand|Select|Wrap|Line Numbers
  1. require "connect.php";
Expand|Select|Wrap|Line Numbers
  1. $query = "SELECT DVD ID, Name Of the DVD, Quantity FROM DVD";
  2.      $stmt = $dbhandle->prepare( $query );
  3.      $stmt->execute();
This is where I am getting the error from.

Below is the whole code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. session_start();
  4.  
  5. ?>
  6.  
  7. <!DOCTYPE HTML>
  8.  
  9. <html>
  10.  
  11.   <head>
  12.  
  13.       <title>Shopping Cart</title>
  14.         <link type="text/css" rel="stylesheet" href="basket.css" />
  15.  
  16.   </head>
  17.   <body>
  18.     <?php
  19.       $action = isset($_GET['action']) ? $_GET['action'] : "";
  20.       $name = isset($_GET['Name Of the DVD']) ? $_GET['Name Of the DVD'] : "";
  21.  
  22.       if($action=='add'){
  23.        echo "<div>" . $name . " was added to your cart.</div>";
  24.      }
  25.  
  26.       if($action=='exists'){
  27.        echo "<div>" . $name . " already exists in your cart.</div>";
  28.      }
  29.  
  30.      require "connect.php";
  31.  
  32.      $query = "SELECT DVD ID, Name Of the DVD, Quantity FROM DVD";
  33.      $stmt = $dbhandle->prepare( $query );
  34.      $stmt->execute();
  35.  
  36.      $num = $stmt->rowCount();
  37.  
  38.      if($num>0){
  39.       echo "<table border='0'>";//start table
  40.  
  41.         // our table heading
  42.             echo "<tr>";
  43.             echo "<th class='textAlignLeft'>DVD Name</th>";
  44.             echo "<th>Quantity</th>";
  45.             echo "<th>Action</th>";
  46.             echo "</tr>";
  47.  
  48.         while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
  49.             extract($row);
  50.  
  51.             //creating new table row per record
  52.             echo "<tr>";
  53.                 echo "<td>{$name}</td>";
  54.                 echo "<td class='textAlignRight'>{$price}</td>";
  55.                 echo "<td class='textAlignCenter'>";
  56.                     echo "<a href='AddToCart.php?id={$id}&name={$name}' class='customButton'>";
  57.                         echo "<img src='images/add-to-cart.png' title='Add To Cart' />";
  58.                     echo "</a>";
  59.                 echo "</td>";
  60.             echo "</tr>";
  61.         }
  62.  
  63.     echo "</table>";
  64. }
  65.  
  66. // no products in the database
  67. else{
  68.     echo "No products found.";
  69. }
  70.  
  71. ?>
  72.   </body>
  73.  
  74. </html>
Thanks for any help.
Jan 9 '14 #1
3 4971
Dormilich
8,658 Expert Mod 8TB
your preparation query fails and therefore ->prepare() returns false.
Jan 10 '14 #2
So what can I do in order for the code to work?
Jan 10 '14 #3
Dormilich
8,658 Expert Mod 8TB
it’s explained in this thread.
Jan 10 '14 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

37
by: Ben | last post by:
Hi, there. Recently I was working on a problem where we want to save generic closures in a data structure (a vector). The closure should work for any data type and any method with pre-defined...
2
by: dmitry.freitor | last post by:
Why would someone call a non-static provate member function from another non-static member function of the same class via the this pointer? Thanks. DF
8
by: nsharma78 | last post by:
Hi, I have a code as follows: class A { public: void print(){cout << "Magic" << endl;} };
5
by: loudwinston | last post by:
Hello, I'm encountering a strange error with PDO. The server is FreeBSD 4.4, PHP 5.1.2, mySQL 4.0.20 with 4.1.18 client libs. I have the following code (usernames and passwords changed to...
18
by: tbringley | last post by:
I am a c++ newbie, so please excuse the ignorance of this question. I am interested in a way of having a class call a general member function of another class. Specifically, I am trying to...
2
by: mahesh | last post by:
Can anyone direct me to the place where i find the solution for the error message "cannot call member function 'X' without object"??? thanks in advance
2
by: Elliott | last post by:
Hello Everyone, I have a function in a header (KeyDialog.h) as such: void setKey(Key&); The function implementation is as such (KeyDialog.cpp): void KeyDialog::setKey(Key& k1) {
3
by: Rowan | last post by:
When I run a small test script I get the following error. ___________________________ PHP Fatal error: Call to a member function prepare() on a non-object in /usr/local/lib/php5/pg_connect.php on...
2
by: church7 | last post by:
Hello, I wrote the following class: In this case, the error message was
10
by: randysimes | last post by:
I am trying to pass uid and pwd to the function CheckPW of the class PWServer. I receive the error pwclient.cpp:41: error: cannot call member function âint PWServer::CheckPW(const char*, char*)â...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.