SilverDevil172 Posted July 1 Share Posted July 1 Using visual studio 1.90.2 Syntax is on the first <p> Error says.. "Syntax error: unexpected token '<'", Also Abstract in the first line is colored as a reserved word. Is this a problem? <?php if(!defined('custom_page_from_inclusion')) { die(); } <p> You have reached Topeka Genealogical Society Abstract data base.</p><br><br> <p> Just click on "Abstract" in the menu to get started. Happy Searching! <p> ?> Quote Link to comment https://forums.phpfreaks.com/topic/322069-new-to-php-dont-understand-this-syntax-error-please-help/ Share on other sites More sharing options...
Solution Barand Posted July 2 Solution Share Posted July 2 When it encounters the "<p>" it is still in the php section of the code and the "<p>" isn't valid php code. You need to exit from php before you enter the html. Move the "?>" line ... 1 Quote Link to comment https://forums.phpfreaks.com/topic/322069-new-to-php-dont-understand-this-syntax-error-please-help/#findComment-1629071 Share on other sites More sharing options...
maxxd Posted July 2 Share Posted July 2 I hope this makes sense - it's how I thought about it a millennia ago when I was learning php - you can mix php and html, but you can't combine them. In other words, as Barand said above, if you want to output html without using the print or echo functionality of php, you need to exit php mode and enter the browser's default mode of html output by using the '?>' php closing tag. By the same regard, if you intend to inject php into your html you need to specifically enter php mode using the '<?php' opening tag. There are obviously exceptions to this (certain templating languages, etc.) but these are things to think about later on - right now don't worry about it. Just make sure all of the php code you're executing within html is contained in the '<?php ?>' tags. Quote Link to comment https://forums.phpfreaks.com/topic/322069-new-to-php-dont-understand-this-syntax-error-please-help/#findComment-1629077 Share on other sites More sharing options...
SilverDevil172 Posted July 3 Author Share Posted July 3 On 7/1/2024 at 7:01 PM, Barand said: When it encounters the "<p>" it is still in the php section of the code and the "<p>" isn't valid php code. You need to exit from php before you enter the html. Move the "?>" line ... Exactly what i needed. Thank you so much!! Quote Link to comment https://forums.phpfreaks.com/topic/322069-new-to-php-dont-understand-this-syntax-error-please-help/#findComment-1629188 Share on other sites More sharing options...
SilverDevil172 Posted July 3 Author Share Posted July 3 On 7/1/2024 at 9:25 PM, maxxd said: I hope this makes sense - it's how I thought about it a millennia ago when I was learning php - you can mix php and html, but you can't combine them. In other words, as Barand said above, if you want to output html without using the print or echo functionality of php, you need to exit php mode and enter the browser's default mode of html output by using the '?>' php closing tag. By the same regard, if you intend to inject php into your html you need to specifically enter php mode using the '<?php' opening tag. There are obviously exceptions to this (certain templating languages, etc.) but these are things to think about later on - right now don't worry about it. Just make sure all of the php code you're executing within html is contained in the '<?php ?>' tags. Thank you for this guidance!! Much appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/322069-new-to-php-dont-understand-this-syntax-error-please-help/#findComment-1629189 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.