I'm trying to check if an email already exist in database and if exists, show message on the screen and don't run the PHPMailer. So I'm using this code below. the email that already exists is not saved in the database as I want, but the PHPMailer still run and the message does not appear.
<?php
include_once 'includes/dbh.php';
require 'email/PHPMailerAutoload.php';
$email = $_POST['emailFor'];
$sql = mysqli_query($conn, "SELECT * FROM `people` WHERE email=?");
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $email);
$stmt->execute();
$result = $stmt->get_result();
$query = $result->fetch_assoc();
if(mysqli_num_rows($result)>0){
echo "This email has already been registered";
} else {
// ==== INSERT VALUES INTO DB
$stmt = mysqli_prepare($conn, "INSERT INTO people (email) VALUES (?);");
mysqli_stmt_bind_param($stmt, 's', $email);
$result = mysqli_stmt_execute($stmt);
}
$mail = new PHPMailer;
$mail ->isSMTP();