检查数据库中是否存在电子邮件

时间:2019-02-05 17:05:14

标签: php mysql sql database android-studio

如果Gmail不存在,我想将用户添加到数据库,此方法从Android应用程序提供Gmail和密码,您能帮我检查一下吗?

function addUser($gmail, $password){
$connection = mysqli_connect(DataBaseManager::HOST,DataBaseManager::USER,DataBaseManager::PASSWORD,DataBaseManager::DATABASENAME);

mysqli_set_charset($connection, "utf8");       
$sqlCommand = "INSERT INTO users(gmail , password )VALUES('$gmail','$password')";

if (mysqli_query($connection, $sqlCommand)) {
      return true;
} else {
      return false;
}

}

1 个答案:

答案 0 :(得分:0)

You can query this to know if a user is already registered.

SELECT gmail
FROM users
WHERE gmail = '$gmail'

If you have 1 row returned, so this user is already registered.

Once you find if this user exists, you can do your query with the INSERT clause.