Forums

wpdb insert problem (1 post)

  1. tifire
    Member
    Posted 8 months ago #

    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.

Reply

You must log in to post.

About this Topic

Tags