MaranV Posted September 8, 2012 Share Posted September 8, 2012 (edited) Hi, new guy to php here. I`m trying to put 2 if conditions (true) together as you can see below.I checked on various sites and from what I understand /$/b/) - remove the / characters to get the actual code I typed instead of this smirking smiley if (is_numeric ($a & $ ) || ($a == $ should be working but it gives me: Parse error: syntax error, unexpected '||' (T_BOOLEAN_OR) in E:\xamp\xampp\htdocs\PHP\week1opdr4\phpweek1opdr4.php on line 14 I have also tried replacing || by &&,syntax error, unexpected '&&' (T_BOOLEAN_AND) <?php $a = $_POST["Invoerlinks"]; $b = $_POST["Invoerrechts"]; if (isset ($_POST["testplus"])) global $a, $b; if (is_numeric ($a & $ ) || ($a == $ { print "$a is wel gelijk aan $b en zijn beide nummers"; } else { print "$a is NIET gelijk aan $b"; } ?> any help on getting these 2 conditions working to produce an echo/print would be appreciated, ALOT (somehow spending 10 hours on your first home work assignment isn`t that motivating ^^) Edited September 8, 2012 by MaranV Link to comment Share on other sites More sharing options...
roy0702 Posted September 8, 2012 Share Posted September 8, 2012 (edited) You lack 1 closing parenthesis, here try this one...Edit: ok I saw some errors, just try this new one if ((is_numeric ( $a) && is_numeric($ b )) || ( $a == $ b )) anyhow, I think the condition is wrong, because the first argument will be ignored if the 2nd is true, and vice versa, maybe you want to change the || condition to && Edited September 8, 2012 by roy0702 1 Link to comment Share on other sites More sharing options...
Ingolme Posted September 8, 2012 Share Posted September 8, 2012 I believe you actually had one extra parenthesis right after the is_numeric() function Link to comment Share on other sites More sharing options...
MaranV Posted September 8, 2012 Author Share Posted September 8, 2012 I believe you actually had one extra parenthesis right after the is_numeric() function yes thanks Ingolme, it looks a bit odd but this is the only way the function works for me roy, I exchanged the || for && and removed the spaces you left after the $ in the b variables and now it seems to be working like a charm if ((is_numeric ( $a) && is_numeric($b )) && ( $a == $b )) gonna mess around with multiple ifs to get echos for different entries, thanks for the help Link to comment Share on other sites More sharing options...
MaranV Posted September 8, 2012 Author Share Posted September 8, 2012 (edited) ok I got the numeric checking down, thanks again but now I`m trying to do the same text (letters only) based EDIT: forgot to place ! at both numeric checkers here is the working code elseif ((! is_numeric ( $a) && ! is_numeric($b )) && ( $a == $b )) SOLVED - thanks Edited September 8, 2012 by MaranV Link to comment Share on other sites More sharing options...
MaranV Posted September 8, 2012 Author Share Posted September 8, 2012 just noticed something ((is_numeric ( $a & $b )) && ( $a == $b )) this works aswell (ironicly i was 1 ( away from a working code myself ....) how is this different from ((is_numeric ( $a) && is_numeric($b )) && ( $a == $b )) is the upper code just shorter or are there any advantages/disadvantages between the 2 ? Link to comment Share on other sites More sharing options...
birbal Posted September 8, 2012 Share Posted September 8, 2012 (edited) this is_numeric ( $a & $b ) and this (is_numeric ( $a) && is_numeric($b ) are not same & is bitwise operator && is logical operator in first case bits will be set where both in $a and $b bits are set. and then the evaluated value will be passed in is_numeric() parameter. if $a or/and $b are string operator will work in characters ascii equivalant, in second case it will check if $a is numeric and also $b is numeric if both are evaluates true it returns true. referencehttp://www.php.net/m....comparison.phphttp://www.php.net/m...ors.bitwise.php Edited September 8, 2012 by birbal 2 Link to comment Share on other sites More sharing options...
MaranV Posted September 8, 2012 Author Share Posted September 8, 2012 thisis_numeric ( $a & $b ) and this (is_numeric ( $a) && is_numeric($b ) are not same & is bitwise operator && is logical operator in first case bits will be set where both in $a and $b bits are set. and then the evaluated value will be passed in is_numeric() parameter. if $a or/and $b are string operator will work in characters ascii equivalant, in second case it will check if $a is numeric and also $b is numeric if both are evaluates true it returns true. referencehttp://www.php.net/m....comparison.phphttp://www.php.net/m...ors.bitwise.php thanks for the answer birbal and another question about global scopes this time I used the global code only once in the first if function, yet my functions even work without having the global code in there and on a subsequent note, all the functions function with out how is this possible? w3schools said I need to enter the global code per function <?php $a = $_POST["Invoerlinks"]; $b = $_POST["Invoerrechts"]; if (isset ($_POST["testplus"])) global $a, $b; //(is_numeric ( $a & $b )) && ( $a == $b ))if ((is_numeric ( $a & $b )) && ( $a == $b )) {print "De waarden van $a en $b en zijn gelijk";}elseif ((is_numeric ( $a) && is_numeric($b )) && ( $a !== $b )) {print "De waarden van $a en $b en zijn niet gelijk"; }elseif ((! is_numeric ( $a) && ! is_numeric($b )) && ( $a == $b )) {print "$a is gelijk aan $b";}elseif ((! is_numeric ( $a) && ! is_numeric($b )) && ( $a !== $b )) {print "$a is NIET gelijk aan $b"; } else { print "$a met $b vergelijken is gelijk aan appels met peren vergelijken, het is niet gelijk";}?> Link to comment Share on other sites More sharing options...
roy0702 Posted September 8, 2012 Share Posted September 8, 2012 (edited) No, you're not using any funtions in your code, the is_numeric function you use is a php built function, wherein you can use anytime without declaring and you dont need any parameters to use. Here is the function that w3schools is pertaining to: http://www.w3schools...p_functions.aspYou can't use any variables from the outside of your declared function if you dont insert them as a parameter (or parameters if you want many).But you can still use them without inserting, just by declaring it anywhere outside the function as a $global variable. Therefore, your variables up there need not to be declared as globals. Edited September 8, 2012 by roy0702 1 Link to comment Share on other sites More sharing options...
MaranV Posted September 8, 2012 Author Share Posted September 8, 2012 No, you're not using any funtions in your code, the is_numeric function you use is a php built function, wherein you can use anytime without declaring and you dont need any parameters to use. Here is the function that w3schools is pertaining to: http://www.w3schools...p_functions.aspYou can't use any variables from the outside of your declared function if you dont insert them as a parameter (or parameters if you want many).But you can still use them without inserting, just by declaring it anywhere outside the function as a $global variable. Therefore, your variables up there need not to be declared as globals. he shoots, he scores thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now