error77
asked on
Syntax Error on PHP Code
Hi all,
I am having trouble with this code:
The error is:
Parse error: syntax error, unexpected '}', expecting ',' or ';' in
Thanks
I am having trouble with this code:
<input type="checkbox" value="1" <?php if ($myvar == '1'){ echo 'checked="yes"' }; ?> />
The error is:
Parse error: syntax error, unexpected '}', expecting ',' or ';' in
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
<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"' ;}
<?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">';
}
if ($myvar == '1') {
print '<input type="checkbox" value="1">';
} else {
print '<input type="checkbox" value="1" checked="yes">';
}
<input type="checkbox" value="1" <?php if ($myvar == '1'){ echo 'checked="yes"' ;} ?> />