1

I am attempting to validate numeric data before adding it to a database, but for some reason it is not triggering the condition for the error message in either positive or negative logic. I can put letters and special characters in, and the code still does not catch the errors. I have read up on many other similar questions that all seemed to be a syntax error, but I cannot find the problem with my code.

<?php
$errorMsg = ""; // error messages variable  
if(is_numeric($Shear)) {
    $Shear = $_POST['Shear'];

} 
else if(!($Shear)) {
    $errorMsg = "You must enter level for Shear Hydraulics.";

}
else {
    $errorMsg = "You must enter numeric data for Shear Hydraulics.";
}

if (!empty($_POST['High'])){  // check if level was entered
    $High = $_POST['High']; 
} 
else if(!is_numeric($High)) { //check if only numbers were used
    $errorMsg = "You must enter numeric data for High Pressure Hydraulic.";  // and if not - add error message
}
else{  
    $errorMsg = "You must enter level for High Pressure Hydraulic.";  // and if not - add error message
}

if (!empty($errorMsg)){ // if there are errors, display them.
    echo ' <script type="text/javascript">
         alert("'.$errorMsg.'");
    </script>
    ';
} ?>

These are the two methods I've tried, and neither catch non numeric data.

0 Answers0