Checking for valid email and if it exists

前端 未结 1 800
既然无缘
既然无缘 2021-01-07 13:32

I have successfully been able to allow users to invite a friend by sending them an email with a unique invite code,

  • however I am trying to add to ability to c
1条回答
  •  耶瑟儿~
    2021-01-07 14:07

    I think your main question is how to check if an email exists in another table. If that's wrong, let me know and I can update my answer :P Here's a rough draft of a function you should be able to use.

    I'm assuming you have these two tables:

    Table 1: users

    ||id||email||name||
    

    Table 2: invites

    ||id||email||inviter_user_id||
    

    You can use this function to check if the email exists in either table

     0) {
                    //email exists
                    $ret_val = true;
                } else {
                    $query = sprintf(
                        "SELECT id FROM invites WHERE email = '%s'",
                        mysqli_real_escape_string($email)
                    );
    
                    $result = mysqli_query($query);
                    $num_rows = mysqli_num_rows($result);
                    if ($num_rows > 0) {
                        //email exists
                        $ret_val = true;
                    }
                }
                return $ret_val;
            }
        }
    ?>
    

    0 讨论(0)
提交回复
热议问题