lundi 21 décembre 2020

Can anyone see why my validation isn't working in PHP?

$bookPrice and $bookYear are being retrieved just fine, so not sure why they aren't passing my validation checks.

// variables used for validation
    $yearRange = array(
        "options"=> array(
        "min_range"=>1800,
        "max_range"=>2100
        )
    );

 //check price is a valid float or integer
    if(!filter_var($bookPrice, FILTER_VALIDATE_FLOAT)
       ||
       !filter_has_var($bookPrice, FILTER_VALIDATE_INT)){
        echo"<p>You have not entered a valid number</p>";
        $error = TRUE;
    }
    
    //check the year is within a reasonable range
    if (!filter_has_var($bookYear, FILTER_VALIDATE_INT, $yearRange)){
        echo"<p>You have not entered a valid Year</p>";
        $error = TRUE;
    }



Aucun commentaire:

Enregistrer un commentaire