I don't know if this code has something wrong with it but I've changed it, along with some other fixes in other functions and now all works just fine. Also I noticed i am missing a $
at if(rows != 0) $result = 2; //mail exists in DB
so this may have caused the problem. Found it after I changed everything... Posting only the function code:
function mailExists($email, $link){
$result = false; //no such mail
$query= "SELECT email FROM users WHERE email = '$email'";
if($stmt = mysqli_prepare($link,$query)){
mysqli_execute($stmt);
mysqli_stmt_store_result($stmt);
$rows = mysqli_stmt_num_rows($stmt);
mysqli_stmt_free_result($stmt);
mysqli_stmt_close($stmt);
}
$_SESSION['rowsDEB'] = $rows;
if($rows > 0) $result = true; //mail exists in DB
return $result;
}