Building a username search by writing custom module My module simply allows a user to type in a user ID # in a field and hit the submit button.  The page should return the username. 

function usersearch_form_submit($form,&amp;$form_state) {
  $query = "SELECT name FROM users WHERE uid = :uid";
  $result = db_query($query,array(':uid' =&gt; $form_state['values']['uid']));
  foreach($result as $user) {
    echo "The username is $user&lt;br&gt;";
  }
  $form_state['rebuild'] =  TRUE;
}


Nothing really happens after I hit the submit button.  I get sent back to the form as if nothing happened.
A form submission handler doesn't use echo to output its result. You need to use a render array to render the result, such as with the following code. I assume usersearch_form() is the form builder function.

function usersearch_form($form, &amp;$form_state) {
  // Add the form elements.

  if (!empty($form_state['username'])) {
    $form['username'] = array(
      '#markup' =&gt; t('The username is %username', array('%username' =&gt; $form_state['username']))
    );
  }

  return $form;
}

function usersearch_form_submit($form, &amp;$form_state) {
  $username = db_query('SELECT name FROM users WHERE uid = :uid', array(':uid' =&gt; $form_state['values']['uid']))-&gt;fetchField();

  $form_state['username'] = $username;
  $form_state['rebuild'] =  TRUE;
}