We help IT Professionals succeed at work.

Syntax Error on PHP Code

error77
error77 asked
on
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

Comment
Watch Question

Loganathan NatarajanLAMP Developer
CERTIFIED EXPERT

Commented:
try


<input type="checkbox" value="1"  <?php if ($myvar == '1'){ echo 'checked="yes"' ;} ?> />
LAMP Developer
CERTIFIED EXPERT
Commented:
corrected,

<input type="checkbox" name="personal" value="checkbox" <?php if($myvar=='1'){ echo "checked=\"true\""; }?>>

Open in new window

Commented:
<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"' ;}
Gary ColtharpSr. Systems Engineer

Commented:
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">';
}

Explore More ContentExplore courses, solutions, and other research materials related to this topic.