Hey I am creating a registration page using PHP and MySQL and I can’t seem to figure out how to put a filter up between my model and controller that doesn’t allow for the use of duplicate emails and usernames in the registration form. Right now it is slipping through my code and registering it despite my attempt at a filter on it. Here is what I have, if you have a simpler way of doing it or see some holes in my code please let me know. Any help would be appreciated!
Model:
function checkEmail ($eMail) {
global $db;
$sql=“SELECT * FROM login WHERE eMail= :em”;
$statement=$db->prepare($sql);
$statement->bindValue(’:em’, $eMail);
$result=$statement->fetch();
$em= $result[‘eMail’];
echo $em;
$statement->closeCursor ();
}
Controller:
case ‘registerAttempt’:
$userName = filter_input (INPUT_POST, ‘userName’);
$password = filter_input (INPUT_POST, ‘password’);
$eMail = filter_input (INPUT_POST, ‘eMail’, FILTER_VALIDATE_EMAIL);
$custType = filter_input (INPUT_POST, ‘custType’);
$em= checkEmail;
if ($userName == NULL || $password == NULL || $eMail == NULL || $custType == NULL || $userName == ‘User Name’|| $password == ‘Password’ || $eMail == ‘E-Mail’) {
$error=“Invalid registration data. Check all fields and try again.”;
include (‘registration.php’);
}
else if ($em==$eMail) {
$error=“Sorry that email already has an account with us. Try again!”;
}
else {
registerAttempt ($userName, $password, $eMail, $custType);
$success=“Congrats, you’ve successfully registered! Please check your email for instructions or head to the log in page!”;
include (‘registration.php’);
}
break;