mercredi 24 décembre 2014

Using if and elseif to check post input

i want to check my post input is it have a right character length, is it contains only character, or is it empty. but it seem i doing it in correctly, can anyone tell me which is caused error in my code? here's my code that i use to validate my name field:



if (empty($_POST['name'])){
$errors[] = "your name can't be empty";}
} elseif (strlen($_POST['name'] < 6|)){
$errors[] = 'your name must have lengh at least 6 character.<br/>';
} elseif (strlen($_POST['name']) > 31|){
$errors[] = 'your name is suppose below 30 character".<br/>';
}else if (!ctype_alpha($_POST['name'])) {
$errors[] = "Please enter only a character.";
}


is it the right way to check my input or is it any a better way in doing this?


Aucun commentaire:

Enregistrer un commentaire