mysqli查询以检查电子邮件是否存在

时间:2018-09-07 08:20:06

标签: php

我正在尝试mysqli查询,以便如果电子邮件已经存在,则php将回显电子邮件已经存在。但没有成功 这是我的代码片段。我在php中是全新的。 谢谢您的帮助。

$conn = new mysqli($servername, $username, $password,$dbname);

if ($_SERVER["REQUEST_METHOD"] == "POST") {
$query = mysqli_query($conn,"SELECT FROM talibeilm_1 WHERE email='$email'");
$res_e = mysqli_query($conn,$query);
 if (mysqli_num_rows($res_e) > 0)
  {
      echo "email already exists";
  }
else {
mysqli_select_db('hussain', $conn);
$sql="insert into talibeilm_1(firstname,lastname,email,gender)
VALUES('$firstname','$lastname','$email','$gender')";
}

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
}

1 个答案:

答案 0 :(得分:1)

查询已执行,您正在尝试执行查询结果。有关更多信息,请查看文档mysqli_query

$query = mysqli_query($conn,"SELECT id FROM talibeilm_1 WHERE email='$email'");
// no need for below line, query is already executed.
// $res_e = mysqli_query($conn,$query);
if (mysqli_num_rows($query) > 0)
{
    echo "email already exists";
}