oobradersoo Posted January 22, 2014 Share Posted January 22, 2014 hello guys just a quick question i have made a html form with php embedded. here is php code: how could i change the code if 1 of the inputs is'nt numeric then it would echo a message saying "insert numeric values" at the minute it echos that if all numeric values are entered. elseif(is_numeric($_POST['number1']) && is_numeric($_POST['number2']) && is_numeric($_POST['number3']) && is_numeric($_POST['number4'])){ echo "please insert number"; Quote Link to comment Share on other sites More sharing options...
Solution ginerjm Posted January 23, 2014 Solution Share Posted January 23, 2014 Uh...... try using OR instead of AND and then look for the negative of the tests ( ! )???? Quote Link to comment Share on other sites More sharing options...
oobradersoo Posted January 23, 2014 Author Share Posted January 23, 2014 that don't work. atm That lines says “if all of the inputs are numeric then echo please put numbers in” but want to change if 1 is not numeric it outputs that Quote Link to comment Share on other sites More sharing options...
ginerjm Posted January 23, 2014 Share Posted January 23, 2014 just realized you had an 'elseif' there. In that case go back to && instead of || (as I suggested) but put a ! in front of a set of parens wrapping all your tests. elseif (!(test && test && test &&test)) { echo error } Quote Link to comment Share on other sites More sharing options...
oobradersoo Posted January 23, 2014 Author Share Posted January 23, 2014 (edited) not working still! Edited January 23, 2014 by oobradersoo Quote Link to comment Share on other sites More sharing options...
oobradersoo Posted January 23, 2014 Author Share Posted January 23, 2014 if(null==($number1 && $number2 && $number3 && $number4)){ echo "Please fill in form above?"; } elseif(is_numeric($_POST['number1']) && is_numeric($_POST['number2']) && is_numeric($_POST['number3']) && is_numeric($_POST['number4'])){ echo "please put numbers in form"; } elseif(isset($_POST['number1']) && isset($_POST['number2']) && isset($_POST['number3']) && isset($_POST['number4'])) {echo "answer:" . ($number1+$number2+$number3+$number4); } i want it to proceed to the last elseif! Quote Link to comment Share on other sites More sharing options...
requinix Posted January 23, 2014 Share Posted January 23, 2014 Where in there is the change that ginerjm told you to make? Quote Link to comment Share on other sites More sharing options...
Mace Posted January 23, 2014 Share Posted January 23, 2014 ginerjm solution is this: elseif(!(is_numeric($_POST['number1']) && is_numeric($_POST['number2']) && is_numeric($_POST['number3']) && is_numeric($_POST['number4']))){ Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted January 23, 2014 Share Posted January 23, 2014 Side note: Are you okay with values like "4e1" and "3.1" being valid numbers? If not, you could use ctype_digit() instead of is_numeric(): http://www.php.net/manual/en/function.ctype-digit.php Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.