Page 1 of 1
PHP MySQL problem
Posted: Thu Oct 21, 2004 7:48 pm
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?
Posted: Thu Oct 21, 2004 8:05 pm
by feyd
[php_man]eval()[/php_man], but understand that it's dangerous unless you know exactly what you are doing.
Posted: Thu Oct 21, 2004 8:34 pm
by TheCaptain
most of it is just includes anyway and the meat of the code is in other files.
Posted: Fri Oct 22, 2004 2:17 pm
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
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
Posted: Fri Oct 22, 2004 2:50 pm
by kettle_drum
You need to edit your code for use in eval(). For instance you dont use <?php ?>.
Posted: Fri Oct 22, 2004 5:19 pm
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!