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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:11:17+00:00 2026-06-15T21:11:17+00:00

For my employee’s table, an e-mail is a unique field. When I insert a

  • 0

For my employee’s table, an e-mail is a unique field. When I insert a new employee, I check on the existance of the email. If it already exists, you get an error message:

    $selectquery ="SELECT * FROM employee WHERE empemail='$empemail'";
    $selectresult=mysql_query($selectquery) or die("query fout " . mysql_error() );
    if(mysql_num_rows($selectresult)==1)
    {
        $errormsgnewemployee = '<p id=notification>The email you entered already exists.</p>';
    }

But how to do it when UPDATING a field? Because if I update an employees data (without changing his mail), it will not let me, because the email already exists. All I can think of it is to UPDATE first, check then if there are 2 records, if there are 2, update it back as it was before.

Is this a good approach or is there a better solution?

EDIT

My own solution is to UPDATE the table having a unique index on the table and using the query error:

    if (mysql_error())
            {
                $errormsgnewemployee = '<p id=notification>Update failed. Please check if the email you entered already exists.</p>';
            }

Because, why else would the user have error if it’s not for the only unique field? In all other cases the update would succeed.

  • 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-15T21:11:18+00:00Added an answer on June 15, 2026 at 9:11 pm

    You can use the same solution, you just need to “fetch this email address, but not mine” to check if there are any other users using it.

    Eg. Before the update, do something like this:

    SELECT 1 FROM employee WHERE empemail = '$empemail' AND id != '$myid';

    Should only return rows where the email belongs to someone else.

    On a side note, there are potential security issues with interpolating variables into SQL queries like that – you shouldn’t do it. And the mysql_* functions are being deprecated should be replaced with PDO or mysqli alternatives.

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

Sidebar

Related Questions

Example: an Employee table with an optional DateOfBirth field can be normalized into two
If table Employee has foreign key for table person, department, when get the entity
I have a table employee that has employee’s benefit data. I have a field
I have a employee table, and a vacations table where each row represents a
I have an employee table, with the following data. For a particular manager, i
Suppose I have employee and department table, employee has foreign key departmentID that is
I have a table: Employee (employeeID) EmployeeRank (rankID, employeeID) Now I have another table
Employee emp = new Employee(); comHandledBySQt.DataSource = emp.GetDataFromTable(1); comHandledBySQt.DisplayMember = FirstName; The above code
I have a table employee having department and address as its property. I want
I have a employee table with columns like emp_id, firstname, lastname, month and year.

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.