I have created a custom table in my wordpress project and I'm using wordpress sql queries to insert/update a user. When an email already exists, it should update the user with the same email, inserting a new user works, but updating one doesn't do anything. No errors either. Can anyone see what I'm doing wrong with my query? Here's my code:
global $wpdb;
$fname = sanitize_text_field(esc_sql($_POST['fname']));
$email = sanitize_email(esc_sql($_POST['email']));
$uniqId = hexdec(uniqid());
$prepare = $wpdb->prepare("SELECT * FROM `wp_registered_customers` WHERE email = %s", [$email]);
$users = $wpdb->get_row($prepare);
if(count($users) > 0){
// wp_send_json_error(ErrorCodes::EMAIL_ALREADY_IN_USE, 400);
$sql = $wpdb->prepare("UPDATE `wp_registered_customers` SET fnmme=%s, email=%s, step1=1, step2=0, step3=0 WHERE email=%s",
[
$fname,
$email,
$email,
]
);
$result = $wpdb->get_results($sql);
} else {
$wpdb->insert('wp_registered_customers', array(
'customer_id' => $uniqId,
'fname' => $fname,
'email' => $email,
'step1' => 1,
));
}