you see I have this query:
$sql = "INSERT INTO visitor( visitor_username, email, PASSWORD )
SELECT * FROM ( SELECT '$username', '$email','$password')
AS tmp WHERE NOT EXISTS
(SELECT admin.admin_username, admin.email FROM admin AS admin
WHERE admin.admin_username = '$username' OR admin.email = '$email'
UNION SELECT staff.staff_username, staff.email FROM staff
AS staff WHERE staff.staff_username = '$username' OR
staff.email = '$email' ) LIMIT 1";
basically if the values (visitor_username, email) does not exist on the admin / staff table, we insert the values, it works pretty good and fast, but a good solution doesnt always bring rainbows.
if we could not insert any values in the table I return this error message
echo "User already exists. Please choose a different email address or username.";
Since I cannot determine which one existed, I would like to have specific case return error for the username or the email address.
Should I split the query (one select, then insert) or is there any other way I'm not finding online to do this in the same query?
My goal is to return a specific error message with this query for example:
"Error: Username already exists" or "Error: Email already exists."
Thanks for checking and trying to help me in advance!.