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 8660249
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:12:34+00:00 2026-06-12T16:12:34+00:00

recently I’ve created a simple registration form and when i try to save the

  • 0

recently I’ve created a simple registration form and when i try to save the data, if i enter an existing username or email i get an error saying that the query is stopped becasue the field already exists

In some cases this is a great feature, and i could use it in the email case.

Im not sure if i have to set this in the form validators or in the config.php or in my module.

here is my save method:

public function saveUser(User $user)
{

    $data = array(
        'username'  => $user->username,
        'email'     => $user->email,
        'password'  => $user->password,
    );

    $id = (int) $user->user_id;

    if ($id == 0) {
        $this->insert($data);
    } elseif ($this->getUser($id)) {
        $this->update(
            $data,
            array(
                'user_id' => $user_id,
            )
        );
    } else {
        throw new \Exception('Form id does not exist');
    }
}

and here is the short error:

Statement could not be executed
...
QLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin' for key 'username'
....

like i said, i could use this error for the email, because i want unique email, but im not sure how to catch this error and display it in a nicer format, maybe like a validation error.

any ideas on this issue?

thanks

  • 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-06-12T16:12:35+00:00Added an answer on June 12, 2026 at 4:12 pm

    This is error returned by your SQL server. To get rid of this you need to remove UNIQUE KEY from your field username.

    As for displaying “nice error message” if user email is duplicate, I’m afraid the only choice you have is to check its existence before executing INSERT.

    I once had database model which was throwing Database_UniqueKey_Exception( $field) which allowed you to do this in quite stylish fashion, but AFAIK Zend doesn’t support special handling for unique key issues and you have to either parse error message (I wouldn’t go there) or check it in advance.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

recently I created a java class Custom Layout Manager , which I want to
Recently we started seeing a problem where the Application_Error event handler (for HttpApplication.Error )
Recently, I try to build WebKit with VS2012. That cost me a lot of
Recently I've created one android application using eclipse and ran it using android virtual
Recently I tried to write a simple compiler on the linux platform by myself.
Recently I've noticed that on occasion I do not get a mayorship notification when
Recently I downloaded Roboguice and gave it a try. In general I like it
Recently I was turned on to the opencv programming library for image and data
Recently, I was given a small task of using graph data structure as core
Recently, I've been dealing with an error with accessing MAPI via the .NET framework

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.