简体   繁体   中英

mysqli query to check email existance

i am trying for mysqli query, so that if email already exist, php will echo email is already exist. but not success here is my snippet of code. i am totally new in php. thank you for your help.

$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;
}
}

Query is already executed, you are trying to execute the query result now. Please have a look on doc mysqli_query for more information.

$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";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM