if (isset($_POST['email'])) {
$email = $_POST["email"];
$check = db::i()->query("SELECT EXISTS(SELECT `email` FROM `s_mailer_list` WHERE `email` = '".$email."' LIMIT 1) AS exist");
try {
$query_result = db::i()->query("INSERT INTO s_mailer_list (added, email, cats) VALUES (NOW(), '$email', ',С сайта,')");
// The query was successful, so the user is subscribed.
echo "success";
} catch (Exception $e) {
// Check if the exception is related to a duplicate entry for the 'email' column.
if ($e->getCode() === 23000) {
// This code represents a MySQL duplicate key error (Integrity constraint violation).
// Handle the case when the email is already in the database.
echo "duplicate";
} else {
// Handle other exceptions if needed.
echo "error";
}
}
}
if(isset($_POST['email'])) {
$email = $_POST["email"];
$check = db::i()->query("SELECT * FROM s_mailer_list WHERE email = '".$email."'");
if($check != null) {echo "Запись уже существует";}
else {
$sql = db::i()->query("INSERT INTO s_mailer_list (added,email,cats) VALUES (NOW(),'$email',',С сайта,')");
echo "OK";
}
}
array(3) {
["message"]=>
string(94) "SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'p@p.ru' for key 'email'"
["function"]=>
string(5) "query"
["sql"]=>
string(86) "INSERT INTO s_mailer_list (added,email,cats) VALUES (NOW(),'p@p.ru',',С сайта,')"
}