mysql – How to search usermeta table

What is the best way to search usermeta to find a user_id based on a meta_value? For example in usermeta table there is a row with user_id = 123 , meta_key = deviceid and meta_value = 45545.
I know the deviceid and I need to find out what user_id is associated with it.
I tried (amongst a million other things) this:

$scaleData = json_decode($reading, TRUE);
$deviceid = $scaleData("imei");
$WhoIsUser = $wpdb->get_var(  $wpdb->prepare("SELECT user_id FROM wp_6cwmmr_usermeta WHERE meta_value = '$deviceid' "));
echo $WhoIsUser ;

I know this is too simple. (fwiw $deviceid does return a valid string.)

user meta – How do I save a Javascript highscore for usermeta?

I created a simple math add-on game for my son using javascript so he can practice his math facts. Basically, he has 90 seconds to correctly answer as many questions as possible.

I want to be able to save and track his high scores using the Usermeta table, but I'm having trouble figuring it out. I know I need to use this function:

update_user_meta( get_current_user_id(), 'high_score', $meta_value);

But I can not determine how I get my "var highScore" from Javascript into the PHP value "$ meta_value". I also need to find a hook or something that will trigger the function once the game is over.

Plugins – How to switch User_Meta in the frontend in a form with PHP

I am trying to create a small form that has only a submit button, and when sending, the user meta should be switched for the WordPress user. The button is present in the frontend after the content of the post and also has an action.

The above was the HTML form code, I can assure it will resonate properly. Then I add the following line to trigger it. That's PHP

if (isset ($ _ GET (& # 39; dark & ​​# 39;))) {
testfun ();
}

This calls a function called testfun, the testfun function is below:

Function testfun () {
$ user_id = get_current_user_id ();
$ theme = get_user_meta ($ user_id, & # 39; theme & # 39 ;, true);
if ($ theme == & # 39; dark & ​​# 39;) {
update_user_meta ($ user_id, & # 39; theme & # 39 ;, & # 39; light & # 39;);
}
otherwise{
update_user_meta ($ user_id, & # 39; theme & # 39 ;, & # 39; dark & ​​# 39;);
}
}

And obviously this code does not work and I can not figure out why. I have the intuition that the way I enter my user ID can be wrong because everything seems to be fine. Anyway, please help me with this code.

Basically, I want to create a button that sets the meta-key & # 39; theme & # 39; for the currently logged-in user. of the user and between the values ​​& # 39; light & # 39; and & # 39; dark & ​​# 39; switches.