I get the following error:
Duplicate entry 'morandi-midnight-train' for key 'post_name'
I want to check if post_name field has already a row defined with a variable and echo an error if it does.
How can i acomplish this?
- post_name has a unique index
Run
SELECT 1 FROM table WHERE post_name = 'morandi-midnight-train' LIMIT 1;before your INSERT query. If the SELECT has any results, show the error.