My validation isn't working right.<?php
if ($submit == "Calculate here"){
if (($diameter == "") || ($spindle == "")){
if(('A' >= $diameter && $diameter <= 'Z') || ('a' >= $diameter && $diameter <= 'z') || ('A' >= $spindle && $spindle <= 'Z') || ('a' >= $spindle && $spindle <= 'z')){
echo "<font color=red>Please enter numbers only.</font>";
}
else{
echo "<font color=red>Please enter a value!</font>";
}
}
else {
$value1 = trim("$diameter");
$value2 = trim("$spindle");
$result = $value1 * ($value2 * (22/7));
//print results
print("The Cutting Speed, V will be</font> ");
printf('%.2f', $result);
print(" m/min.");
}
}
?>
Using a form, I'm capturing 2 variables. $diameter and $spindle.
Using the 2 variables, they are calculated using the formula above, and output the result.
However, I can't validate correctly. As in.. the statements don't appear at the right time.
For example, if both variables do not have a value, and I click "submit", the error statement would be "Please enter numbers only." instead of "Please enter a value!".
Please help! Thanks!