Runing php embed in html

Website URL

(http://clientserver1.42web.io/?i=2)

Error Message

Uncaught SyntaxError: Unexpected token ‘<’ (at slideshow - php.php:1:2)

Other Information

this is the html code:

<script src="slideshow - php.php"></script>

this is the code i'm trying to unsuccessfuly run:
 <?php
    echo "<p>WELCOME</p>" ;
?>

to mention that this is my first project at infinityfree.com

thank you

the missing html code line is:

<script src="slideshow - php.php"></script>

@shadmot please put your code inside this:
```
Code goes here
```

7 Likes

In addition to that, seems like you’re trying to include your file as a script, while it isn’t so. You can use an iframe to integrate pages or other websites that have a compatible X-Frame-Options policy in an HTML file. See the MDN web docs for that tag.

5 Likes

I formatted the messages for you so the code is readable. Please note that using HTML code is a supported way to format your messages here, so any HTML code you post here will be rendered, not shown as-is. To avoid that, please wrap it in code blocks. You can use Markdown, BBCode or HTML to format your posts.

As for the code itself, the <script> tag is used to load in Javascript code from other files, which is then executed by the browser. Including PHP code works differently, you can do that from within other PHP code, for example:

<?php require 'slideshow - php.php'; ?>

Right now, the <script> tag will cause the browser to try to access the PHP file, which will cause the server to execute the PHP code, which returns the output <p>WELCOME</p>. Because that output is not valid Javascript code (it’s HTML), it doesn’t work.

8 Likes

the code suddenly appeard
thank you.

I took the idea from examples I saw, but I’ll try your option.
thank you very much!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.