Error: getting double query while trying to insert with prepared statement PHP for my OTP

I am having an issue, my code works fine, however, the only issue i am facing is my otp insert code is inserting double otp at once, i cant find any loop causing double entry, or any double query execution.

My code

<?php

//forgot password start

if (isset($_POST["forgot_form"])) {

if (isset($_COOKIE['hvt_user']) == true){

?>

<script type="text/javascript" nonce="<?php echo $nonce ?>">

$("#forgot-button").removeAttr("disabled");

$("#forgot-button").css("opacity", "1");

$("#hvt_ajax_response_div").show();

$("#hvt_ajax_responses_inner_div").css({ 'background': '#a81a1a', 'display': 'block'});

$("#hvt_ajax_responses_inner_div").html("Error: Cannot send reset password OTP. <br/> You are logged in.");

$("#hvt_ajax_response_div").delay(6000).fadeOut("fast");

</script>

<?php

exit();

}

$form_forgot_form = $_POST['forgot_form'];

$form_form_forgot_password_email = $_POST['form_forgot_password_email'];

$form_form_forgot_password_email = mysqli_real_escape_string($con_escape_string, $form_form_forgot_password_email);

if (empty($form_form_forgot_password_email)){

?>

<script type="text/javascript" nonce="<?php echo $nonce ?>">

$("#forgot-button").removeAttr("disabled");

$("#forgot-button").css("opacity", "1");

$("#hvt_ajax_response_div").show();

$("#hvt_ajax_responses_inner_div").css({'background': '#a81a1a', 'display': 'block'});

$("#hvt_ajax_responses_inner_div").html("Error: Email cannot be left empty.");

$("#hvt_ajax_response_div").delay(6000).fadeOut("fast");

</script>

<?php

exit();

} else {

if (!preg_match("/^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,}$/", $form_form_forgot_password_email)) {

?>

<script type="text/javascript" nonce="<?php echo $nonce ?>">

$("#forgot-button").removeAttr("disabled");

$("#forgot-button").css("opacity", "1");

$("#hvt_ajax_response_div").show();

$("#hvt_ajax_responses_inner_div").css({'background': '#a81a1a', 'display': 'block'});

$("#hvt_ajax_responses_inner_div").html("Error: Invalid email address.");

$("#hvt_ajax_response_div").delay(6000).fadeOut("fast");

</script>

<?php

exit();

} else {

$form_form_forgot_password_email = strtolower($form_form_forgot_password_email);

}

}

$select = "SELECT * FROM users WHERE email = ?";

$get_select = mysqli_prepare($con_select, $select);

if (!$get_select) {

die("mysqli_prepare failed: " . mysqli_error($con_select));

}

mysqli_stmt_bind_param($get_select, "s", $form_form_forgot_password_email);

mysqli_stmt_execute($get_select);

$run_get_email = mysqli_stmt_get_result($get_select);

if (mysqli_num_rows($run_get_email) !== 0){

$array_run_get_id = mysqli_fetch_array($run_get_email);

$ii_user_id = $array_run_get_id["user_id"];

$ii_status_active_blocked_or_not_verified = $array_run_get_id["status_active_blocked_or_not_verified"];

if ($ii_status_active_blocked_or_not_verified == "blocked"){

?>

<script type="text/javascript" nonce="<?php echo $nonce ?>">

$("#forgot-button").removeAttr("disabled");

$("#forgot-button").css("opacity", "1");

$("#hvt_ajax_response_div").show();

$("#hvt_ajax_responses_inner_div").css({ 'background': '#a81a1a', 'display': 'block'});

$("#hvt_ajax_responses_inner_div").html("Error: Could not start reset, this account is blocked.");

$("#hvt_ajax_response_div").delay(4000).fadeOut("fast");

</script>

<?php

exit();

} else if ($ii_status_active_blocked_or_not_verified == "not-verified"){

} else if ($ii_status_active_blocked_or_not_verified == "verified"){

} else {

}

$time = time();

$registered_date = date("Y-m-d H:i:s", $time);

include 'functions.php';

$enter_type_of_verification = "account-password-reset-logged-out";

$enter_code = $e_token;

$enter_date_and_time = $registered_date;

$enter_user_id = $ii_user_id;

$enter_status = "not-used";

$enter_method = "email";

$query = "INSERT INTO otp (type_of_verification, code, date_and_time, user_id, status, method) VALUES (?, ?, ?, ?, ?, ?)";

$stmtx = mysqli_prepare($con_insert, $query);

if (!$stmtx) {

die("mysqli_prepare failed: " . mysqli_error($con_insert));

}

mysqli_stmt_bind_param($stmtx, "ssssss", $enter_type_of_verification, $enter_code, $enter_date_and_time, $enter_user_id, $enter_status, $enter_method);

if (mysqli_errno($con_insert)) {

die("mysqli_stmt_bind_param failed: " . mysqli_error($con_insert));

}

mysqli_stmt_execute($stmtx);

if (mysqli_errno($con_insert)) {

die("mysqli_stmt_execute failed: " . mysqli_error($con_insert));

} else {

}

if (mysqli_stmt_affected_rows($stmtx) > 0) {

$get_id_query = "SELECT * FROM users WHERE user_id = ?";

$get_id_statement = mysqli_prepare($con_select, $get_id_query);

mysqli_stmt_bind_param($get_id_statement, "s", $ii_user_id);

mysqli_stmt_execute($get_id_statement);

$run_get_id = mysqli_stmt_get_result($get_id_statement);

if (mysqli_num_rows($run_get_id) == 0){

} else {

$array_run_get_id = mysqli_fetch_array($run_get_id);

$ii_email = $array_run_get_id["email"];

}

$from_which_rr = "HVT Forex <[email protected]>";

$subject_to = "OTP - Account password reset";

$text = "Your HVT Fx academy account reset One Time Passcode [OTP] is ";

$full_stop = ".";

$data = array(

'from' => $from_which_rr,

'to' => $ii_email,

'subject' => $subject_to,

'text' => $text.$enter_code.$full_stop,

);

$boundary = uniqid();

$body = '';

foreach ($data as $key => $value) {

$body .= "--{$boundary}rn";

$body .= "Content-Disposition: form-data; name="{$key}"rnrn";

$body .= "{$value}rn";

}

$body .= "--{$boundary}--";

$headers = array(

"Content-Type: multipart/form-data; boundary={$boundary}",

);

$versw = curl_init("https://api.mailgun.net/v3/mail.example.com/messages");

curl_setopt($versw, CURLOPT_POST, true);

curl_setopt($versw, CURLOPT_RETURNTRANSFER, true);

curl_setopt($versw, CURLOPT_USERPWD, "api:xxxxxxxxxxxx");

curl_setopt($versw, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);

curl_setopt($versw, CURLOPT_HTTPHEADER, $headers); // Set headers

curl_setopt($versw, CURLOPT_POSTFIELDS, $body);

$run_curl = curl_exec($versw);

curl_close($versw);

//var_dump($run_curl);

$array_respo = json_decode($run_curl, true);

//var_dump($array_respo);

@$z_id = $array_respo["id"];

@$z_message = $array_respo["message"];

setcookie('reset_cookie', $reset_password_code."|".$receiver_email, time() + (7 * 60), "/"); // 7 minutes expiry date

?>

<script type="text/javascript" nonce="<?php echo $nonce ?>">

window.location.href="<?php include "includeprefixlink.php" ?>reset-password?success=<?php echo $reset_password_code ?>";

</script>

<?php

} else {

}

} else {

?>

<script type="text/javascript" nonce="<?php echo $nonce ?>">

$("#forgot-button").removeAttr("disabled");

$("#forgot-button").css("opacity", "1");

$("#hvt_ajax_response_div").show();

$("#hvt_ajax_responses_inner_div").css({ 'background': '#a81a1a', 'display': 'block'});

$("#hvt_ajax_responses_inner_div").html("Error: Could not reset. <br/> Account not found.");

$("#hvt_ajax_response_div").delay(4000).fadeOut("fast");

</script>

<?php

exit();

}

}

//forgot password end

?>

I have tried using database transactions, nothing works.

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật