Jump to content

New to PHP Don't understand this syntax error. Please Help.


Go to solution Solved by Barand,

Recommended Posts

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>

?>

  • Solution

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 ...

image.png.7b3649ddb0f7e519c319302e776915b6.png

  • Thanks 1

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.

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 ...

image.png.7b3649ddb0f7e519c319302e776915b6.png

Exactly what i needed.   Thank you so much!!

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.   

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.