Why can't I have hyphens in my db_query()
Make sure you use proper placeholders in your db queries, as per the Drupal API.

E.g in D7: 

$query = db_query("SELECT * from {foo} WHERE bar = :bar", array(':bar' =&gt; $bar));


or

$query = db_select('foo', 'f')
  -&gt;fields('f')
  -&gt;condition('bar', $bar, '=')
  -&gt;execute();


More info:


Database API
db_query
db_select


UPDATE: Now the the original SQL has been posted, the problem appears to be


Lack of use of fetchObject, fetchAssoc etc.. on the database result


You should be able to use

if($result-&gt;rowCount() == 1){
  $name = $result-&gt;fetchObject()-&gt;NAME;
}


As an aside, better to limit the query if you only want one record returned, e.g

$name = db_select('ukeys', 'u')
  -&gt;fields('u', array('NAME'))
  -&gt;condition('uid', $user-&gt;uid)
  -&gt;condition('EMAIL', $user-&gt;mail)
  -&gt;condition('GENERATEDKEY', $ukey)
  -&gt;range(0,1)
  -&gt;execute()-&gt;fetchfield();


That will return the $name value only, or FALSE if no record exists.