Well that's basically what I'm trying to do.
I have a form that saves into the database, now if the email in this case, already exist, it gives me the error message that " user already exist.
and since I am echoing out the values from the database into the form fields it gives me that " user already exist" error every time i push update.
If don't echo out the value, when I'm updating the form, it saves an empty email address, or filter_validate_Email
function tells me that the email is not valid.
I tried and succeed when fixed the problem with check boxes but that's kind of messy and ugly so I am trying if else statement but with no luck. Any tips on how to manage this ?
Ill send you some code.
if(email_exists($_POST['email'])===($_POST['email'])){
}
if(email_exists($_POST['email'])){
$errors[] = 'email already registered';
}
With that statement i was thinking of, if the $_POST email is equal to $_POST email.
do nothing, but if the email exist from email_exist function. error email already exist.
if(empty($errors)){
set_profile_info($_POST['firstname'],
$_POST['lastname'],
$_POST['username'],
$_POST['email'],
$_POST['about']);
}
}
email_exists query
function email_exists($email){
global $db;
$st = $db->prepare("SELECT * FROM user WHERE email=?" );
$st->bindParam(1, $email);
$st->execute();
if($st->rowCount() ==1){
return true;
}
else{
return false;
}
}
There are probably millions of other ways, but i cant figure anything else. thanks