Skip to:
Content
Pages
Categories
Search
Top
Bottom

any idea why my sql isnt working?

  • @firetag

    Participant

    I am developing a plugin and my sql $wpdb->query( $sql); continues to return false and I have no idea why.

    I have another save function using just about the same code just a different table and it works great! I was thinking maybe you need to register each table and bind it to the plugin, but then why is the other table able to be written to… anyway here is the code (does anything stick out to you?)

    Code:
    function save(){
    global $wpdb,$bp;
    if( $this->id ){
    //update
    $sql = $wpdb->prepare(
    “UPDATE {$bp->mlgfantasy->user_table} SET
    owner_id =%d,
    pick_one =%s,
    pick_two =%s,
    pick_three =%s,
    pick_four =%s
    WHERE id = {$this->id}”,

    $this->owner_id,
    $this->pick_one,
    $this->pick_two,
    $this->pick_three,
    $this->pick_four
    );
    } else{
    //save
    $sql = $wpdb->prepare(
    “INSERT INTO {$bp->mlgfantasy->user_table} (
    owner_id,
    pick_one,
    pick_two,
    pick_three,
    pick_four
    ) VALUES (
    %d, %s, %s, %s, %s
    )”,
    $this->owner_id,
    $this->pick_one,
    $this->pick_two,
    $this->pick_three,
    $this->pick_four);
    }
    $result = $wpdb->query($sql);
    if ( !$this->id ) {
    $this->id = $wpdb->insert_id;
    }
    if($result)
    return true;
    return false;
    }

Viewing 4 replies - 1 through 4 (of 4 total)
  • @firetag

    Participant

    here is what gets passed to the $wpdp->query()

    UPDATE wp_bp_mlgfantasy_user SET pick_one = ‘Walshy’, pick_two = ‘Neighbor’, pick_three = ‘Roy’, pick_four = ‘Legit’ WHERE owner_id = 1

    is that what it should look like?

    @crashutah

    Participant

    Try copy and pasting it into PHPMyAdmin and see what error it throws. If it doesn’t throw an error, then the SQL is good and something else is wrong with the way the SQL’s being run.

    @firetag

    Participant

    Hey thanks so much it worked to help debug the sql …. It was actually a really dumb mistake….wrong col names… lol

    @crashutah

    Participant

    No worries. We’ve all done that. PHPMyAdmin gives better error messages sometimes;-)

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘any idea why my sql isnt working?’ is closed to new replies.
Skip to toolbar