Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP syntax displaying in HTML source

Tags:

html

php

In my CMS I've added this code <div><?php include("my_contact_form.php") ?></div> which updates to a db. I can see it there OK.

I have this php code in my display page after the db call:

$content = $row['content']; 

when I echo $content inside the body this is displayed in the HTML source:

<div><?php include("my_contact_form.php") ?></div>

How could this possibly be? Why wouldn't it show my contact form? If anyone has any suggestions I would be extremely grateful. Cheers.


1 Answers

It sounds like you are storing the PHP code in the database and expecting it to be executed when you echo it. This won't happen, as far as the PHP interpreter is concerned it's just text (not PHP code) so it will just echo it.

You can force PHP to interpret (/run) the code in your string with the eval() function, but that comes with a large number of security warnings.

Storing code in the database is rarely the right solution.

like image 81
Brenton Alker Avatar answered Nov 28 '25 13:11

Brenton Alker