baggs1981 Posted September 3, 2017 Share Posted September 3, 2017 Can anyone tell me what is wrong with this: <?php $anything = "yes"; if (isset($anything)) { ?> <div> <?php if ($anything == "yes") { ?> blatext <?php } ?> </div> <?php } ?> I'm using Dreamweaver CC build 9314 The issue was in a 1000 line page and stripping everything out to get to the cause of error eventually leaves the above. See attached pics error1.png is the above page, error2.png shows the further yellow code errors that show on the complete page. If I delete the closing </div> entirely, it works. If I change the first isset to any other type of if rule, it works. If I add an extra </div> after blatext, it works. As mentioned above the problem is within a 1000 line page, on that page the issue is compounded and there are 9 of the code problem yellow </div> I have spent hours trying to figure this out, I've sat and counted out the <div> </div> pairs, checked while sections seperately by pasting them into separate pages and the above code is the only bit that has an issue. Please help Quote Link to comment https://forums.phpfreaks.com/topic/304849-mind-numbing-issue-very-basic-code-bug/ Share on other sites More sharing options...
Barand Posted September 3, 2017 Share Posted September 3, 2017 Your two versions of the code (posted and image) are different, so which do you expect us to try to debug? The image code incorrectly uses "=" instead if "==" for the comparison, if that helps. Quote Link to comment https://forums.phpfreaks.com/topic/304849-mind-numbing-issue-very-basic-code-bug/#findComment-1550634 Share on other sites More sharing options...
ginerjm Posted September 3, 2017 Share Posted September 3, 2017 And - please - learn how to use the echo command and cease switching in and out of php mode. That is 'mind-numbing' code!!! <?php $anything = "yes"; if (isset($anything)) { echo '<div>'; if ($anything == "yes") { echo 'blatext'; } echo '</div>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/304849-mind-numbing-issue-very-basic-code-bug/#findComment-1550643 Share on other sites More sharing options...
Jacques1 Posted September 3, 2017 Share Posted September 3, 2017 HTML fragments scattered all over the application code are even worse. As far as old school PHP templating goes (which is inherently messy), switchting between the modes is fine. That's why they exist. You should use the verbose syntax for control structures, though. <?php $age = 44; ?> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Title</title> </head> <body> <div> <?php if ($age >= 21): ?> Welcome to the site. <?php else: ?> You're too young to visit this site. <?php endif; ?> </div> </body> </html> If you want to do it properly, use a template engine like Twig. This not only gives you a much better syntax and plenty of useful features. It also prevents a large amount of security problems which PHP code notoriously suffers from. 1 Quote Link to comment https://forums.phpfreaks.com/topic/304849-mind-numbing-issue-very-basic-code-bug/#findComment-1550646 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.