0

I am using an HtML and PHP. I have to check the Table with the If condition using PHP for Example

<?php if($status==0) {?>
<td><input type='text' name='test' id='test' value=''>
<?php }?>
<?php else (if($status==2) && ($status==1)) {?>
<td><input type='text' name='test' id='test' value=''>
<?php }?>

Am getting eror as unexpected else and unexpected boolean.........

Is it wrong?

4
  • It might be helpful to show some code and what you expect to get as a result... Your question is a bit ambiguous. Commented Mar 25, 2011 at 5:21
  • 2
    Very vague. Can you add a code snippet perhaps? Commented Mar 25, 2011 at 5:21
  • Sounds like you have a PHP syntax problem. You're going to have to post more information and a more specific question if you want help though. Commented Mar 25, 2011 at 5:21
  • @John, @Canuteson : there was a code portion, but it was not formated as such -- and, so, didn't appear ;; I've edited the question to format it properly, and the code now appears. Commented Mar 25, 2011 at 5:28

5 Answers 5

1

Looking at your code, it seems you have two syntax errors.


First, the following lines :

<?php } ?>
<?php else (if($status==2) && ($status==1)) { ?>

Should go in only one PHP tag : there should be no closing + beginning tags between the } and the else.


Second, the opening parenthesis should not be between the else and the if -- but arround the condition :

<?php } else if(($status==2) && ($status==1)) { ?>
Sign up to request clarification or add additional context in comments.

Comments

1

While the others have covered your syntax error, I'll cover your logic error:

<?php } else if(($status==2) && ($status==1)) { ?>

This checks to see if $status is equal to 2, and then also checks that $status is equal to 1.

$status can't be both 1 and 2 at the same time.

If $status is 1, then the if check evaluates to:

<?php } else if((false) && (true)) { ?>

... which is false, meaning the condition won't match.

You probably want ||, the "logical or" operator instead of &&, the "logical and" operator:

<?php } else if(($status==2) || ($status==1)) { ?>

Here's the PHP manual page on logical operators.

Comments

0

you have syntax error while saying else if.... I would rewrite the code as following:

<?php if($status==0) :?>
<td><input type='text' name='test' id='test' value=''>
<?php else if (($status==2) && ($status==1)) :?>
<td><input type='text' name='test' id='test' value=''>
<?php endif; ?>

2 Comments

This is my code <?php if ($vCertificateStatus==0) :?> <td><input type="text" name="CertificateDate" id="CertificateDate" value="" /> <?php else if(($vCertificateStatus==-1)&&($vCertificateStatus==1)) :?> <td><input type="text" name="CertificateDate" id="CertificateDate" value="<?php echo $vReceivedDate;?>" /> <?php endif; ?> still i am getting error as syntax error, unexpected T_IF, expecting ':'
yeah definitely its your code with slidght modification on else if and instead of {} i am using :
0

Here is syntax error

<?php else (if($status==2) && ($status==1)) {?>

Change it to

<?php elseif(($status==2) && ($status==1)) {?>

EDIT

Space is not allowed between elseif. Also you have logical error as others pointed change your && to ||

Note: Note that elseif and else if will only be considered exactly the same when using curly brackets When using a colon to define your if/elseif conditions, you must not separate else if into two words, or PHP will fail with a parse error.

<?php if ($vCertificateStatus==0):?> 
<td><input type="text" name="CertificateDate" id="CertificateDate" value="" /> 
<?php elseif(($vCertificateStatus==-1) || ($vCertificateStatus==1)):?> 
<td><input type="text" name="CertificateDate" id="CertificateDate" value="<?php echo $vReceivedDate;?>" />
<?php endif; ?>

2 Comments

This is my code <?php if ($vCertificateStatus==0) :?> <td><input type="text" name="CertificateDate" id="CertificateDate" value="" /> <?php else if(($vCertificateStatus==-1)&&($vCertificateStatus==1)) :?> <td><input type="text" name="CertificateDate" id="CertificateDate" value="<?php echo $vReceivedDate;?>" /> <?php endif; ?> still i am getting error as syntax error, unexpected T_IF, expecting ':'
@akila: If it is working and helped you Please accept my answer by clicking on the right arrow sign.
0

Insteed of {...} you need to use : and endif;

<?php if($status==0) :?>
<td><input type='text' name='test' id='test' value=''>

<?php elseif(($status==2) && ($status==1)) :?>
<td><input type='text' name='test' id='test' value=''>
<?php endif; ?>

?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.