I have an array of emails and I want to check if all those emails are valid by verifying with my database. I want to add the invalid emails (if any) to an empty array. I'm not too familiar with MySQL so I need some help with doing this. This is what I have so far in my PHP file:
<?php
$conn = mysqli_connect($servername, $username, $password, $db);
$conn->select_db($db);
if($conn->connect_error) {
die("Connection failed " . $conn->connect_error);
}
echo "Connected successfully\n";
$tags = preg_split("/\,/", $_POST['tags']);
$invalidEmails = array();
$count = 0;
$result = $conn->query("SELECT mail FROM dej_colleagues");
for ($i = 0; $i < sizeof($tags); $i++) {
$trim_brackets = trim($tags[$i], '[]');
$trim_quotes = trim($trim_brackets, '"');
while ($row = mysqli_fetch_array($result, MYSQL_ASSOC)) {
if ($trim_quotes == $row["mail"]) {
$count += 1;
}
else {
array_push($invalidEmails, $tags[i]);
}
}
}
if (sizeof($tags) == $count) {
echo "good";
}
?>
My database connection was successful, but even if the emails in my tags array exist in the database, it is not detecting it. Also, the database column has 100k entries so if you know a more efficient method please let me know.