PHP MySQL problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
TheCaptain
Forum Newbie
Posts: 3
Joined: Thu Oct 21, 2004 7:47 pm

PHP MySQL problem

Post by TheCaptain »

Im currently working on a site that is mostly php driven. Anyway I have a table in a db that has the fields name and content. What im doing is getting the content out of the db and displaying it. The problem is I put php code in the content field and when I get it and echo it it doesnt parse the code. How do I retrive php code from a db and then run it?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

[php_man]eval()[/php_man], but understand that it's dangerous unless you know exactly what you are doing.
TheCaptain
Forum Newbie
Posts: 3
Joined: Thu Oct 21, 2004 7:47 pm

Post by TheCaptain »

most of it is just includes anyway and the meat of the code is in other files.
TheCaptain
Forum Newbie
Posts: 3
Joined: Thu Oct 21, 2004 7:47 pm

Post by TheCaptain »

Ok here is the code I have. I have allready connected so dont worry about that.

Code: Select all

$result = mysql_query("SELECT * FROM pages WHERE name='$page'");
$row = mysql_fetch_array($result); 
eval($rowїcontent]);
In this case $row[content] would contain

Code: Select all

<? include "news.php"; ?>
But I get the error

Code: Select all

Warning: Unexpected character in input: ''' (ASCII=92) state=1 in content.php on line 10

Parse error: parse error, unexpected '<' in content.php(10) : eval()'d code on line 1
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

You need to edit your code for use in eval(). For instance you dont use <?php ?>.
User avatar
sakaveli
Forum Commoner
Posts: 60
Joined: Tue Apr 06, 2004 9:42 am

Post by sakaveli »

i had a similar prob, eval() worked for me too.

read up on it, but its nt so bad once your sure u know what you want!
Post Reply