Add value to every user in data field
This is because you're not filtering the users when you grab them using db_select. This will also grab the "Anonymous" user (uid 0). When you try to save that user, this error happens most likely. Putting a simple if(!empty($dude-&gt;uid)) within your foreach loop should fix this issue. Or excluding uid 0 from your db_select query using the NOT EQUALS condition like so:

$updateAllDudes = db_select('users', 'uu')
  -&gt;fields('uu')
  -&gt;condition('uid', 0, '&lt;&gt;')


Or by using the NOT IN condition:

$updateAllDudes = db_select('users', 'uu')
  -&gt;fields('uu')
  -&gt;condition('uid', array(0), 'NOT IN')


See here


  if you need to edit all users (I am setting a default value for a custom field), you need to strip uid=0 from the list and deal with it as a special case.