Jump to content

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))
  • Like 1
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.