how to connect to database for form submission
I think there is problem with the condition in the query. Try changing it

$result = db_select('users', 'u')

-&gt;fields('u',array('uid'))

-&gt;condition('u.name', $name,'=')

-&gt;execute()

-&gt;fetchField();


You better use Webform Module to create a form without any issues!!


  Webform is the module for making surveys in Drupal. After a
  submission, users may be sent an e-mail "receipt" as well as sending a
  notification to administrators. Results can be exported into Excel or
  other spreadsheet applications. Webform also provides some basic
  statistical review and has and extensive API for expanding its
  features.