PHP form validation submit problem?

Posted by TaG on Stack Overflow See other posts from Stack Overflow or by TaG
Published on 2010-04-09T02:57:45Z Indexed on 2010/04/09 3:03 UTC
Read the original article Hit count: 169

Filed under:
|

My code is suppose to save a year like 1999 to the mysql database but it wont. It will check to see if the user has entered only numbers and is at least 4 numbers long or if nothing has been entered correctly but it wont save the correct year? How can I fix this problem.

Here is the PHP code.

if(isset($_POST['year']) && intval($_POST['year']) && strlen($_POST['year']) == 4) {
    $year = mysqli_real_escape_string($mysqli, $purifier->purify(htmlentities(strip_tags($_POST['year']))));
} else if($_POST['year'] && strlen($_POST['year']) < 4) {
    echo '<p class="error">year is not correct!</p>';
}  else if($_POST['year'] == NULL) {
  // do something
}

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql