Title: Error using $wpdb in a plugin
Last modified: August 20, 2016

---

# Error using $wpdb in a plugin

 *  [bahumba](https://wordpress.org/support/users/bahumba/)
 * (@bahumba)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/error-using-wpdb-in-a-plugin/)
 * I am trying to create a plug-in which uses a table that I added into my database.
   The plugin creates a widget which has a multiple choice question form. When the
   form submits, it goes to my submit.php file which is located in the same plugin
   folder.
 * On the submit.php file, I am trying to run a query to update some values in the
   table I built by using this:
 * `$update = $wpdb->update( my_table, array ( guesses=>$numGuesses), array (id=
   >$id));`
 * Although I have the “global $wpdb” defined, I still receive “Fatal error: Call
   to a member function get_results() on a non-object”. The widget successfully 
   uses the $wpdb as it queries the same table to pull the data for the questions(
   uses $wpdb->get_results()). I don’t understand what I am doing wrong to make 
   this not work, for I have looked over both files and nothing appears to be different.
 * Does anybody have any thoughts on what it could be?

Viewing 4 replies - 1 through 4 (of 4 total)

 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [13 years, 10 months ago](https://wordpress.org/support/topic/error-using-wpdb-in-a-plugin/#post-2938914)
 * Is $wpdb an object?
 *  Thread Starter [bahumba](https://wordpress.org/support/users/bahumba/)
 * (@bahumba)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/error-using-wpdb-in-a-plugin/#post-2938924)
 * I believe it is a class. If you try to echo $wpdb you get an error saying something
   along the lines of “could not convert to string from class”.
 *  [Andrew Nevins](https://wordpress.org/support/users/anevins/)
 * (@anevins)
 * WCLDN 2018 Contributor | Volunteer support
 * [13 years, 10 months ago](https://wordpress.org/support/topic/error-using-wpdb-in-a-plugin/#post-2938929)
 * Try var dumping it
 *  Thread Starter [bahumba](https://wordpress.org/support/users/bahumba/)
 * (@bahumba)
 * [13 years, 10 months ago](https://wordpress.org/support/topic/error-using-wpdb-in-a-plugin/#post-2938998)
 * When I do the var_dump on the submit page, it returns NULL. But on the page where
   my query works, it returns:
 * object(wpdb)#1 (70) { [“show_errors”]=> bool(false) [“suppress_errors”]=> bool(
   false) [“last_error”]=> string(0) “” [“num_queries”]=> int(81) [“num_rows”]=>
   int(2) [“rows_affected”]=> int(1) [“insert_id”]=> int(11096) [“last_query”]=>
   string(53) ” SELECT * FROM wp_brain_in_gear ” …. with a lot more after that

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Error using $wpdb in a plugin’ is closed to new replies.

## Tags

 * [$wpdb-&gt;update](https://wordpress.org/support/topic-tag/wpdb-gtupdate/)
 * [query](https://wordpress.org/support/topic-tag/query/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [bahumba](https://wordpress.org/support/users/bahumba/)
 * Last activity: [13 years, 10 months ago](https://wordpress.org/support/topic/error-using-wpdb-in-a-plugin/#post-2938998)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
