I want to have it that if the "tags_name" already exists in the database it will display an error in php rather than a fatel error message.
if(isset($_POST['NewTag']))
{
$tags_name= $_POST['tags_name'];
$stmt = $DBcon->prepare("INSERT INTO category (tags_name) VALUES(:tags_name)");
$stmt->bindparam(':tags_name', $tags_name);
if ($stmt->execute()) {
$successMSG = "Succesfull";
} else {
$errMSG = "Entry already exists";
}
}
I'm currently getting this error "Fatal error: Uncaught PDOException: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'testing' for key 'tags_name' ...." instead my errMSG.