Building a username search by writing custom module
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;
}