There are 2 main issues in your code:
-
Your
$wpdb->get_row($prepare)
will return either an object or anull
, so you can’t doif(count($users) > 0)
because$users
is not an array.To fix that, just use
if ( $users )
. -
There’s a typo here:
SET fnmme=%s
— the field name should befname
.
So you should just need to correct those issues and your code would work as expected.
However, you should not use $wpdb->get_results()
to run an UPDATE query, and instead,
-
You can use
$wpdb->query()
. -
Or in your case, you should use
$wpdb->update()
like so: (just replace the$sql = $wpdb->prepare(...); $result = $wpdb->get_results($sql);
in your code with the code below)$wpdb->update( 'wp_registered_customers', array( 'fname' => $fname, 'email' => $email, 'step1' => 1, 'step2' => 0, 'step3' => 0, ), array( 'email' => $email ) );
But, are you sure you want to set
email
to the value of$email
? 🤔
Additionally, I don’t think it’s necessary to call esc_sql()
here:
$fname = sanitize_text_field(esc_sql($_POST['fname']));
$email = sanitize_email(esc_sql($_POST['email']));