Greetings all!
I have an "employees" table, I have an add and edit page for this table.
I have a "check for duplicates" for the "email" field working on the add page - and it is working great! <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=question&id=13306&image=1&table=forumtopics' class='bbc_emoticon' alt=':)' />
Problem is that I want to make sure that on the edit page, the email can't be changed to another email that is already in the DB.
So, I apply the same "check for duplicates" code from the add page - but the problem is, is that even if the email address isn't updated, it still complains that the address is already in the database.
This of course is due to the fact that the check is simple - in that it checks to see if that email that is being re-submitted (the entire set of fields gets re-submitted on the edit page) is present - even if it is its own row.
So, I know how I would do this in straight PHP:
1.) I would do a pre-check to see if the previous data (original row data before form submit) and new data (after form submit) were the same on the email field - if the same, do nothing. If different (meaning the email was changed) then apply the duplicate check.
-or-
2.) Modify my "check for duplicate" query to select employee_id AND email, and when doing the "duplicate" check, somehow exclude the employee id (using a WHERE and NOT clause) that we are working with.
For the second, I am not sure of SQL code to use (I was thinking of something like this?):
$strSQLExists = "select employee_id,email from employee where email='$values[email]' AND employee_id NOT='$values[employee_id]'";
I can experiment with this, but was wondering if there was a more simple/effetive way with PHPRunner, or if anyone has come across this before - or just some good coding standards recommendations!
Thanks all!