PHP form validation submit problem

Posted by TaG on Stack Overflow See other posts from Stack Overflow or by TaG
Published on 2010-04-08T21:33:49Z Indexed on 2010/04/08 21:43 UTC
Read the original article Hit count: 222

Filed under:
|

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
}

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql