Title: sql query help
Last modified: August 19, 2016

---

# sql query help

 *  Resolved [islandcastaway](https://wordpress.org/support/users/islandcastaway/)
 * (@islandcastaway)
 * [15 years, 3 months ago](https://wordpress.org/support/topic/sql-query-help-3/)
 * Can someone please help me with this sql query:
 * `$image = $wpdb->get_var($wpdb->prepare("SELECT image FROM $wpdb->wordtube WHERE
   vid = $wordtubeId"));`
 * I am getting this error:
 * `WordPress database error You have an error in your SQL syntax; check the manual
   that corresponds to your MySQL server version for the right syntax to use near''
   at line 1 for query SELECT image FROM wordtube WHERE vid = made by require, require_once,
   include, boposts_show`
 * The query is working but I get this in php-errors.log
 * What am I missing?

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

 *  [alxvallejo](https://wordpress.org/support/users/alxvallejo/)
 * (@alxvallejo)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/sql-query-help-3/#post-1939334)
 * Probably too late for this one but have you tried WHERE vid = ‘$wordtubeId'”));?
 *  Thread Starter [islandcastaway](https://wordpress.org/support/users/islandcastaway/)
 * (@islandcastaway)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/sql-query-help-3/#post-1939335)
 * > RE: alxvallejo wrote:
   > Probably too late for this one but have you tried WHERE vid = ‘$wordtubeId'”));?
 * I thought that I posted my fix, guess not, and not sure why [@alxvallejo](https://wordpress.org/support/users/alxvallejo/)
   post isn’t here I just got via email subscription.
 * Newayz I got it fixed with
 * > $image = $wpdb->get_var(“SELECT image FROM ($wpdb->wordtube) WHERE vid = ($
   > wordtubeId)”);}
 * Cheers
 *  [alxvallejo](https://wordpress.org/support/users/alxvallejo/)
 * (@alxvallejo)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/sql-query-help-3/#post-1939336)
 * Just curious, were you placing this inside a function? I’m fairly new at plugin
   development and I’m trying to figure out if I’m inserting variables correctly.
 *  Thread Starter [islandcastaway](https://wordpress.org/support/users/islandcastaway/)
 * (@islandcastaway)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/sql-query-help-3/#post-1939337)
 * Yes.
 * To be specific I added it to the plugin “best related posts” to grab the thumbnail
   from a post that had “wordtube” content.
 * I have no clue if my code is 100% correct, but its working and it doesn’t throw
   any errors.
 * Cheers

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

The topic ‘sql query help’ is closed to new replies.

## Tags

 * [query](https://wordpress.org/support/topic-tag/query/)
 * [sql](https://wordpress.org/support/topic-tag/sql/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 4 replies
 * 2 participants
 * Last reply from: [islandcastaway](https://wordpress.org/support/users/islandcastaway/)
 * Last activity: [14 years, 7 months ago](https://wordpress.org/support/topic/sql-query-help-3/#post-1939337)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
