Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6784245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:58:00+00:00 2026-05-26T16:58:00+00:00

I am querying database records to check if a username already exists this way:

  • 0

I am querying database records to check if a username already exists this way:

$q = Doctrine_Query::create()
        ->from('Tcc_Model_User u')
        ->where('u.Username = ?', $input['Username']);

 $object = $q->fetchOne();

  if(is_object($object)) {

  // not sure what to do here

 } else {

 // ok to record

What I cannot make it work is how to show a message that username is already taken next to the Username field of the submitted form. Could please anyone help me? Really appreciated any help. Thank you

EDITED:

Thanks to Drew010 I solved the above problem by adding:

 $form->getElement('Username')->addError('Sorry, that username is already taken!');

in the first of the conditional statement. Thank again drew010.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T16:58:00+00:00Added an answer on May 26, 2026 at 4:58 pm

    Since you are using Zend_Form, there is a validator that can do this for you.

    See Zend_Validate_DbNoRecordExists

    They give an example for validating that a given username does not exist in the database.

    Here is an example from one of my applications, the third validator checks that the username does not already exist:

        $this->addElement('text', 'username', array(
            'label' => 'User Name:',
            'required' => true,
            'validators' => array('NotEmpty'),
            'decorators' => $this->elementDecorators,
            'validators' => array(
                array('StringLength', true, array('min' => 4,
                    'messages' => array(
                        Zend_Validate_StringLength::TOO_SHORT =>
                        'Account username must be at least %min% characters'
                    )
                )),
                array('Regex', true, array('pattern' => '/^\w(?:[\w\d\.\-_]+)(?:\w|\d)$/',
                    'messages' => array(
                        Zend_Validate_Regex::NOT_MATCH =>
                        "The username contained invalid characters"
                    )
                )),
                array('Db_NoRecordExists', true, array(
                    'table' => 'accounts', 'field' => 'username',
                    'messages' => array(
                        Zend_Validate_Db_NoRecordExists::ERROR_RECORD_FOUND =>
                        "An account with the username '%value%' is already registered"
                    )
                ))
            )
        ));
    

    Also, for future reference, if you do extended validation you can’t do with a validator, you can add an error to a specific form element like this:

    if ($something_was_wrong) {
        $form->getElement('username')
             ->addError('Username already exists!');
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to select distinct or unique records from a database I am querying.
i'm querying a database like this: SELECT * from Log WHERE cookieId IN (select
How can I retrieve data from the database by querying records between two dates
AM querying an access database, selecting records from two tables, in vb6 using the
I'm trying to do a simple exercise querying a database from JS using XMLHTTPrequest
Django's ORM supports querying from a specific database (when multiple are defined in your
I'm querying the database first to get all records associated with a certain userid,
I am collecting data from the calllog, putting it into a database, and querying
I'm querying the database for a single record that matches the id passed in
I am querying a database for results and trying to convert them into JSON

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.