PintilieVasile Posted August 30, 2014 Share Posted August 30, 2014 Hy guys. Today i started to learn php and in my first script (a calculator) i have this error message Parse error: syntax error, unexpected T_LOGICAL_AND, expecting ')' in /home/gameforce/public_html/33/calculator.php on line 5 On localhost i don't have this error. The php code from "calculator.php" it's: <?php $num1 = $_POST['num1']; $num2 = $_POST['num2']; $calculator = $num1 + $num2; if (empty($num1 and $num2)) { echo 'Ambele campuri trebuie sa fie completate.<br>'; else { echo 'Rezultatul este ' . $calculator . '.<br>'; if ($calculator >= 10) { echo 'Rezultatul este mai mare decat 10.<br>'; } else { echo 'Rezultatul nu este mai mare decat 10.'; } } } ?> What's the problem? Thanks and sorry for my bad english. Quote Link to comment https://forums.phpfreaks.com/topic/290758-t_logical_and-expecting-syntax-error/ Share on other sites More sharing options...
CroNiX Posted August 30, 2014 Share Posted August 30, 2014 Around line 5: if (empty($num1 and $num2)) { Error: unexpected T_LOGICAL_AND, expecting ')' The error is saying that it doesn't expect the AND there, and it's expecting a ) instead. This is because empty() only accepts one argument, so you need to split that into two empty() statements. if (empty($num1) AND empty($num2)) 1 Quote Link to comment https://forums.phpfreaks.com/topic/290758-t_logical_and-expecting-syntax-error/#findComment-1489410 Share on other sites More sharing options...
CroNiX Posted August 30, 2014 Share Posted August 30, 2014 You probably also want to use an OR instead of an AND, otherwise the error will only trigger if both are empty. You'd also want to do that check before you try to add the 2 numbers together. Quote Link to comment https://forums.phpfreaks.com/topic/290758-t_logical_and-expecting-syntax-error/#findComment-1489411 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.