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

  • Home
  • SEARCH
  • 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 8609147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:48:26+00:00 2026-06-12T03:48:26+00:00

I have a register form with email which should be unique. What I want

  • 0

I have a register form with email which should be unique. What I want to do is, if someone fills in an email which is alreday registered for another user, this someone to see a message, written by me, not something like

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin@domain.com' for key 'UNIQ_1483A5E9E7927C74'

I tried this in the repository class:

public function getSameFriends ($email)
    {
        $q = $this->createQueryBuilder('f');

        $q->select('f')
          ->where('f.email = :email')      
          ->setParameter('email', $email);

        return $q->getQuery()->getSingleScalarResult();
    }

and then this in the controller:

$em = $this->getDoctrine()->getEntityManager();
        $count = $em->getRepository('EMMyFriendsBundle:Friend')
                                    ->getSameFriends($friend->getEmail());
        if($count != 0)
        {
            $this->get('session')->setFlash('notice', 'There already is a friend with this email!');
            return $this->redirect($this->generateUrl('home_display'));
        }

but I get an exception that

No result was found for query although at least one row was expected.
500 Internal Server Error - NoResultException

I don’t need the result of the query, just to know if the results are 1 or 0. Do you have any idea how to make this?

  • 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-12T03:48:27+00:00Added an answer on June 12, 2026 at 3:48 am

    You can do:

    return count($q->getQuery()->getResult());
    

    BTW, have you looked at the ‘uniqueEntity’ validation constraint? It provides the functionality you need out of the box:

    http://symfony.com/doc/current/reference/constraints/UniqueEntity.html

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

Sidebar

Related Questions

I have this website (C#/ASP.NET) with a form where the user can register for
In my web application i have registration form, when user register i want to
I have a homepage which I want a registration form on, to do this
I have a form, where user can register their personal information for a club,and
I have a user registration Form. If a new User register their account in
i have two tables which form part of my login/register system: these are userlogin
I have a class user which looks like this: public class User { public
I have registration form, which is saving user info in 'tblusers' -> 'Username', but
I have a registration form which contains a read-only textarea. I want to require
I have a register form which is post data without refresh page! My problem

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.