PDA

View Full Version : save php code in a mysql database field!!



shyne
07-10-2007, 08:59 PM
Hi

I am not sure if this can be done since I couldn't find a way to output a php code I have saved in a mysql database table field.
This is what I want to do:

I want to save a php code in a mysql table "BLOCKS" field name "CODE" for ex:


echo "This is why I am hot lol";
$qblocks = "SELECT * FROM `acyn_pages_blocks` WHERE page_id = '$page_id'";
$rblocks = mysql_query($qblocks);
if (!$rblocks){
die ("Could not query the database:<br />Houston! we have a problem here. ". mysql_error());
}
$b = mysql_fetch_array($rblocks, MYSQL_ASSOC);

echo "blah blah and anything else in php code";


now in my pages.php I want to output the code saved in the mysql database. I can call the code but it prints it as plain php code and does not output the result of the code. Can someone please tell me how can I achieve this so it prints out the actual result of the code, whatever it is.
A little example would be nice. I really need this to work

Thanks

Twey
07-10-2007, 09:37 PM
http://www.php.net/eval

But, this is fairly ugly.

shyne
07-10-2007, 10:01 PM
Is it!!!

Can you give me an example with my php code above as to how can I use EVAL(); to include all that code. I am kinda not getting it at all.

How do I save a php code in the database. I tried to save that above code but it gives out an error. I mean like before submitting it to the database there has to be some kind of fucntion where it safely saves the code to the database.

Thanks

Twey
07-10-2007, 10:40 PM
How do I save a php code in the database.The same way you save anything else. You did remember to use mysql_real_escape_string() on it, right?