Jump to content

T_LOGICAL_AND, expecting ')' Syntax Error


PintilieVasile

Recommended Posts

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.

 

Link to comment
https://forums.phpfreaks.com/topic/290758-t_logical_and-expecting-syntax-error/
Share on other sites

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))

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.