Page 1 of 1

php code in database

Posted: Fri Aug 27, 2004 2:24 pm
by ol4pr0
Oke maby kinda stupid but there must be a way to be able to do this.

i tried out a simple thing like the following

I had this code in a database field

Code: Select all

<?
echo 'Hello World';
?>
Than i retrieved that row from the database trying to have it displayed on the page. However it didnt do that.

When just using text like "Hello World", it would nicely print out "Hello World"

Is there a way to be able to retrieve html and php code from the database ? Or what is the best way to do this.

Posted: Fri Aug 27, 2004 2:30 pm
by feyd
[php_man]eval[/php_man].. be careful though ;)

Posted: Fri Aug 27, 2004 2:36 pm
by ol4pr0
Howcome what is the downside of using that ? Is there a better way ?


edit: Every html code has to be echo'd with php .. Hmm can that be changed ?

Posted: Fri Aug 27, 2004 2:40 pm
by feyd
blindly eval'ing code can create problems if someone is able to insert code that say... deletes the entire site. :)

Posted: Fri Aug 27, 2004 2:46 pm
by ol4pr0
What is a other option.. besides putting the whole code in pages lol, i want to be possibel to get as much as i can from the database. However some pages include some queries. So how to get them into the code that i am retrieving from the database

Lets say

#in database
<?
<body>
</body>
?>
Now i want to insert content. which is also stored in database.
Which needs to be between the body tags. or tables.. or whatever..

Posted: Fri Aug 27, 2004 2:52 pm
by feyd
if you want it for content... look into using templates. for instance, assume the following is stored in a field inside the database

Code: Select all

&lt;body&gt;&#123;DATA&#125;&lt;/body&gt;

Code: Select all

echo str_replace('{DATA}','this is inserted content',$text);