Sam
Sam

Reputation: 328

Why is this WordPress Database query not working?

Can somebody tell me why the following code is not working as I intended it to. I want the $token to be inserted into ami_st_token_aut of my wp_users field where the id is the id of the user currently logged in.

$token = $_GET['token'];
$services = $_GET['services'];
global $current_user;
get_currentuserinfo();
$wpdb->query("UPDATE $wpdb->users SET ami_st_token_aut = ".$token." WHERE ID = ".$current_user->ID."");

Upvotes: 1

Views: 570

Answers (1)

Shakti Singh
Shakti Singh

Reputation: 86346

Check the $current_user->ID if it is not empty.

If the field type is to store string values enclose the value in quotes for ami_st_token_aut

$wpdb->query("UPDATE $wpdb->users SET ami_st_token_aut = '".$token."' 
             WHERE ID = ".$current_user->ID."");

Upvotes: 1

Related Questions