Title: wpdb insert problem
Last modified: August 20, 2016

---

# wpdb insert problem

 *  [tifire](https://wordpress.org/support/users/tifire/)
 * (@tifire)
 * [14 years, 9 months ago](https://wordpress.org/support/topic/wpdb-insert-problem-1/)
 * I use wpdb insert query to insert a role into the database. Here is the code:
   ////////////////////////////////////////////////////
   $wpdb->insert({$wpdb->base_prefix}bp_my_markers, array( ‘id’=> ’31’, ‘name’ =
   > ‘myname’,’address’ => ‘2500 main street’, ‘lat’ => ‘47.612823’, ‘lng’ => ‘-
   122.345673’, ‘type’ => ‘bar’)); ////////////////////////////////////////////////////
 * but it doesn’t work.
 * Then I tried the following code to do the same thing.
    ////////////////////////////////////////////////////
   $wpdb->query( $wpdb->prepare( “INSERT INTO {$wpdb->base_prefix}bp_my_markers (
   id, name, address, lat, lng, type)VALUES (’31’, ‘myname’, ‘2500 main street’,‘
   47.612823’,’ 122.345673′,’bar’)”)); ////////////////////////////////////////////////////
 * This time it works.
 * I really don’t know what’s wrong with my $wpdb->insert code. Could someone tell
   me?
 * I know the latter way can be used to protect queries against SQL jnjection attacks,
   but are there any other differences between the two? Which one is better?
 * Thanks.

The topic ‘wpdb insert problem’ is closed to new replies.

## Tags

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

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 0 replies
 * 1 participant
 * Last reply from: [tifire](https://wordpress.org/support/users/tifire/)
 * Last activity: [14 years, 9 months ago](https://wordpress.org/support/topic/wpdb-insert-problem-1/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
