Results 1 to 4 of 4

Thread: save php code in a mysql database field!!

  1. #1
    Join Date
    Mar 2007
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default save php code in a mysql database field!!

    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:
    Code:
    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

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    http://www.php.net/eval

    But, this is fairly ugly.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Mar 2007
    Posts
    54
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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
    Last edited by shyne; 07-10-2007 at 10:37 PM.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    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?
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •