How to get logged user id? I am developing a moule which has one page asking for email frequency; when the user selects and save it, I save it in the user table, but it doesn't work. It works only when I hard code the user ID.

global $user;
$uuid = $user-&gt;uid;

function emailf_form_submit($form, &amp;$form_state) {
  $bb = $form_state['values']['emailf'];
  $query = db_update('users')
    -&gt;fields(array('email_f' =&gt; $bb))
    -&gt;condition('uid', $uuid, '=')
    -&gt;execute(); 

  drupal_set_message('Email frequency successfully changed');  
}
It works when $uuid is initialized inside the function. 

function emailf_form_submit($form, &amp;$form_state) {
  global $user;
  $uuid = $user-&gt;uid;

  $bb = $form_state['values']['emailf'];
  $query = db_update('users')
    -&gt;fields(array('email_f' =&gt; $bb))
    -&gt;condition('uid', $uuid, '=')
    -&gt;execute(); 

  drupal_set_message('Email frequency successfully changed');  
}