PHP form validation submit problem
- by TaG
Every time I try to submit the form and I have not entered nothing in the year field I get Incorrect year! how can I still submit the form without having to enter a year. In other words leaving the year field blank and not getting a warning?
Here is the PHP code.
if(preg_match('/^\d{4,}$/', $_POST['year'])) {
$year = mysqli_real_escape_string($mysqli, $_POST['year']);
} else {
$year = NULL;
}
if($year == NULL) {
echo '<p class="error">Incorrect year!</p>';
} else {
//do something
}