0

I am writing a code to match form input data with user table in wp, but its not working proper, either condition is true or false, its giving same message. please help me to resolve it.

  function email_form_code() {
    echo '<form action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" method="post">';
    echo '<p>';
    echo '<p>';
    echo 'Your Email (required) <br />';
    echo '<input type="email" name="email" value="' . ( isset( $_POST["email"] ) ? esc_attr( $_POST["email"] ) : '' ) . '" size="40" />';
    echo '</p>';
    echo '<p><input type="submit" name="submit" value="Send"/></p>';
    echo '</form>';
}

function checkpoint_email() {
    global $wpdb;
    if(isset($_POST['submit'])){
    $email = sanitize_email($_POST['email']);
    if(!is_email($email)) {
        echo '<div class="error"><p>Invalid e-mail!</p></div>';
     }
    $datum = $wpdb->get_results("SELECT COUNT(*) FROM wp8p_users WHERE $current_user->user_email = $email");
    if($datum < 0) {
       echo "Email Verified";
    }
    else {
         echo "Email Not Verified";
    }   
}
}
function ec_shortcode() {
    ob_start();
    checkpoint_email();
    email_form_code();
    return ob_get_clean();
}
add_shortcode( 'av_email_cform', 'ec_shortcode' );
?>
  • When you say it always gives the same message, is that the verified message or the not verified message? – Tom J Nowell Mar 18 at 12:54
  • True or False, in every condition its give same message "Email Verified" – Amar Verma Mar 18 at 15:57
  • and if we add use !== in condition then its shows "Email Not Verified" every time, its true or False, give the same message. – Amar Verma Mar 18 at 15:59
  • And where is the form the $_POST data coming from? Have you checked the values of $_POST['email'] and the current user email to confirm they have the expected values? Is the user logged in? – Tom J Nowell Mar 18 at 16:44
  • yes. user is logged in. you may check it at learn.amarverma.com/email it will show guest message, once u log in, it will show user name and email id and below a input field to accept email id. I want to check and verfiy this input email id which is stored in user table. i have this task to complete. – Amar Verma Mar 18 at 17:22
0

Your conditional check is the wrong way around, it should be > not <.

But more importantly, why are you doing a raw SQL query at all, just use the standard functions, e.g. get_user_by:

$user = get_user_by( 'email', $email );
if ( !$user ) {
    // there is no user with that email
}

Also, submit is an incredibly generic name for a form input to check, use something more specific, like av_email_cform_submit.

You can also replace your action="' . esc_url( $_SERVER['REQUEST_URI'] ) . '" with action="". You also have a double <p><p> in your form.

|improve this answer|||||
  • Thanks a Ton! I was looking for its solution since long time. Thanks again. – Amar Verma Mar 19 at 13:21
  • one issues is there. if I logged in my account, and I put other email id which is stored in database, its showing verified. I want Current user can only verify his email id only. so please guide how to restrict by current user only. – Amar Verma Mar 19 at 13:48
  • ooh, neither this answer nor your original code checks the current user specifically, you should ask how to get the current users email in a new Q – Tom J Nowell Mar 19 at 13:50
  • problem solved. Thanks for your guidance. Is there any tutorial/coding to create a plugin for scheduled popup? – Amar Verma Mar 20 at 9:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.