samedi 9 mai 2015

Multiple logical operators in if..else staterment in php

firstname and lastname are being submitted from a HTML form.

In PHP i want to check that both of them must be atleast 3 characters long and maximum upto 18 characters. How can i check it in an if else statement

Example code is below

$f = $_POST['firstname'];
$l = $_POST['lastname'];
if((strlen($f) < 3 || strlen($f) > 16) && (strlen($l) < 3 || strlen($l) > 16))
{
    echo "Firstname and lastname must be between 3 and 16 characters";
    exit();
}

It is not working what i have done wrong.....

Thanks for help and I hope you understand my problem

Aucun commentaire:

Enregistrer un commentaire