jarv Posted May 29, 2013 Share Posted May 29, 2013 Please help, I get the following php error: unexpected T_IF here is my code: echo '<input type="radio" name="BGimageID" value="'.$row2['BGimageID'].'" '.if($row2['pages.BGimageID']==$row2['bgimages.BGimageID']){ echo " checked" }' /><img src="../images/'.$row2['BGimage'].'" width="150" />'; Link to comment https://forums.phpfreaks.com/topic/278561-unexpected-t_if/ Share on other sites More sharing options...
dannon Posted May 29, 2013 Share Posted May 29, 2013 Please help, I get the following php error: unexpected T_IF here is my code: echo '<input type="radio" name="BGimageID" value="'.$row2['BGimageID'].'" '.if($row2['pages.BGimageID']==$row2['bgimages.BGimageID']){ echo " checked" }' /><img src="../images/'.$row2['BGimage'].'" width="150" />'; You cannot use the 'if' keyword in the middle of functions or variable assignments. Take a look at this http://www.php.net/manual/en/language.expressions.php Sorry for horrible wording. Link to comment https://forums.phpfreaks.com/topic/278561-unexpected-t_if/#findComment-1433001 Share on other sites More sharing options...
gizmola Posted May 29, 2013 Share Posted May 29, 2013 As Dannon pointed out, you can not concatenate a string onto a language construct (in this case your if statement). However, since your goal is output html in this section of code, I'd recommend that you utilize PHP's ability to intermix html and php code. <?php // prior code here // Now end php block ?> <input type="radio" name="BGimageID" value="<?= $row2['BGimageID'] ?>" <?= $row2['pages.BGimageID'] == $row2['bgimages.BGimageID'] ? ' checked' : ''; ?> /> <img src="../images/<?= $row2['BGimage'] ?>" width="150" /> <?php //More php code if needed Link to comment https://forums.phpfreaks.com/topic/278561-unexpected-t_if/#findComment-1433017 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.