Title: $wpdb-&gt;prepare with variable
Last modified: August 19, 2016

---

# $wpdb->prepare with variable

 *  [Steppppo](https://wordpress.org/support/users/steppppo/)
 * (@steppppo)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/wpdb-gtprepare-with-variable/)
 * I am trying to use a variable with wpdb->prepare but it’s not working for some
   reason.
 * I’ve built this statement in my code:
 * “UPDATE wp_eventuser_tbl SET fname = %s, lname = %s, active = %d WHERE id = %
   d”, Steven, Nowickcow, 0, 10
 * and set it equal to $strQuery.
 * but, when i execute this line:
 * $wpdb->query( $wpdb->prepare( $strQuery ) );
 * it doesn’t work.
 * however, I can cut and past the statement exactly and replace $strQuery and the
   code updates perfectly.
 * any clues as to why it won’t execute using $strQuery?

Viewing 1 replies (of 1 total)

 *  [dpolant](https://wordpress.org/support/users/dpolant/)
 * (@dpolant)
 * [16 years, 5 months ago](https://wordpress.org/support/topic/wpdb-gtprepare-with-variable/#post-1154349)
 * You have to do it like this:
 *     ```
       $strQuery = "UPDATE wp_eventuser_tbl SET fname = %s, lname = %s, active = %d WHERE id = %d";
   
       $wpdb->query($wpdb->prepare( $strQuery, "Steven", "Nowickcow", 0, 10 ) );
       ```
   
 * You can’t set a variable equal to a quoted string plus a list of unquoted values.
   PHP doesn’t understand that you want to move that whole thing as a bunch of different
   arguments for $wpdb->prepare.

Viewing 1 replies (of 1 total)

The topic ‘$wpdb->prepare with variable’ is closed to new replies.

## Tags

 * [$wpdb->prepare](https://wordpress.org/support/topic-tag/wpdb-prepare/)
 * [prepare](https://wordpress.org/support/topic-tag/prepare/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 1 reply
 * 2 participants
 * Last reply from: [dpolant](https://wordpress.org/support/users/dpolant/)
 * Last activity: [16 years, 5 months ago](https://wordpress.org/support/topic/wpdb-gtprepare-with-variable/#post-1154349)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
