Kieran Wood
Kieran Wood

Reputation: 1

Wordpress update query not working

I have an update query which is not working for me. I am able to make selects quite happily on the same page but I cannot get an update statement to work. The table is not a part of wordpress so Im wondering if that could be it or if I have just got something wrong.

$query = "UPDATE   login_count SET `count` = '100' WHERE  `user_id` = $userID ";
$insrt = $wpdb->query($query);

Upvotes: 0

Views: 760

Answers (3)

Sujan Shrestha
Sujan Shrestha

Reputation: 1040

$insrt = $wpdb->update( 
'login_count', //table_name
array( 
    'count' => '100',   // string   
), 
array( 'user_id' => $user_id ),  //Where Condition
array( 
    '%d',   // value1
), 
array( '%d' ) 
);

Upvotes: 2

Kamal Lama
Kamal Lama

Reputation: 700

Try this,

$insrt = $wpdb->update(
                'login_count',    //table_name
                array('count'=>'100'),//data
                array('user_id'=>$userID),//where
                array('%s'),//data format
                array('%s')
                    );

Upvotes: 3

Callan Heard
Callan Heard

Reputation: 727

Try this ..user_id = {$userID} ";

Edit

See: Use a $variable inside a SQL string?

Upvotes: 0

Related Questions