Link to home
Start Free TrialLog in
Avatar of error77
error77

asked on

Syntax Error on PHP Code

Hi all,

I am having trouble with this code:

<input type="checkbox" value="1"  <?php if ($myvar == '1'){ echo 'checked="yes"' }; ?> />

Open in new window


The error is:

Parse error: syntax error, unexpected '}', expecting ',' or ';' in

Thanks

Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India image

try


<input type="checkbox" value="1"  <?php if ($myvar == '1'){ echo 'checked="yes"' ;} ?> />
ASKER CERTIFIED SOLUTION
Avatar of Loganathan Natarajan
Loganathan Natarajan
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
<input type="checkbox" value="1"  

<?php

if ($myvar == '1')
 { echo 'checked="yes"' };

?> />

When you look at it like this, you can see that the semicolon is in the wrong place:

if ($myvar == '1')
 { echo 'checked="yes"' ;}
to get rid of the nested php issue:

if ($myvar == '1') {
         print  '<input type="checkbox" value="1">';
}  else {
         print '<input type="checkbox" value="1" checked="yes">';
}