any idea why my sql isnt working?
-
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;
}
- The topic ‘any idea why my sql isnt working?’ is closed to new replies.