Retrieving email addresses with special characters using MySQL query
I am fairly new to PHP and Mysql. The question I am going to ask will be
begging for someone to tell me to use prepared statements so first of all
let me say I am learning this, but not quite there yet. I have a query
that looks to see if an email address is in the database. The email
addresses may contain unusual characters like - , / | "" etc etc. I can't
seem to retrieve them - here is my code (the repeatemail is coming from a
form). Works perfectly with email addresses without this characters.
$checkemail = $_POST['repeatemail'];
$checkemail = mysqli_real_escape_string($con, $checkemail);
//Perform database to see if email exists
$query = "SELECT email FROM scorers WHERE email = '{$checkemail}'";
$result = mysqli_query($con, $query);
$row = mysqli_fetch_row($result);
if ($row[0] == $checkemail){
echo "found";
} else {
echo "not found";
}
As it stands I have wondered if the escape string is stripping the unusual
characters and therefore once its queried it been altered but that doesn't
seem to be the case. Also, I have no problem entering addresses like
simon.o'malley@nhs.uk but just can't check them with the above code.
Looked up many explanations regarding UTF etc but its a bit above my head
at this point. Could someone give me a solution to this....how do I alter
the code above so it will pick out these funky email addresses? Many
thanks
No comments:
Post a Comment