I recently started programming in php and made some nice progress (if I say it myself). Now I stumbled upon some problems.
What I have is some if
statements with a mysql
query
inside it.
if(empty($_POST['Email'])){
$error_Email = "No email";
$errors++;
}elseif(!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $_POST['Email'])){
$error_Email = "Invalid email";
$errors++;
}elseif ($mysqli->query("SELECT * FROM Members WHERE Email LIKE '".$_POST['Email']."'")->num_rows == 0){
$error_Email = "[TEST] NOT IN DB";
}else{
$error_Email = "[TEST] IN DB";
}
So I have a couple problems with my code. Lets say that me@this.com
is in the database. I only want to see [TEST] IN DB
when I type me@this.com
exactly, not if me@
, not if this.com
, ... only when I type in me@this.com
.
My 2nd problem is that this piece of code can be manipulated because I put the search criteria in the query directly.
So is there a safer way of achieving what I want above with the query returning a row only if the match is exact.