First of all, don't use mysql_real_escape_string()
; the old mysql_
API is deprecated, so consider switching to PDO or mysqli instead.
Second, you should consider using input filtering; $_POST['dgt']
may not exist at all, so use filter_input()
.
Third, you should use numeric values to compare against the output of strlen()
; although PHP will treat "32"
as a number, it's better to be explicit.
Lastly, if a name must be either 32 or 40 long, you can simply add the condition:
$name = filter_input(INPUT_POST, 'dgt', FILTER_UNSAFE_RAW);
if (empty($name) || (strlen($name) != 32 && strlen($name) != 40)) {
print "This is not a name.";
}
Alternatively, use in_array()
:
if (empty($name) || !in_array(strlen($name), array(32, 40))) {
print "This is not a name.";
}