SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,

    Is it possible to store PHP code in the database then have it processed after it comes out.

    Say I wanted to store:

    echo ($name=="Pete") ? "Yes" : "No";

    Is it possible to get this to display yes or no on the page, considering that that above code would be stored in the database.

    Thanks
    Pete

  2. #2
    Serial Publisher silver trophy aspen's Avatar
    Join Date
    Aug 1999
    Location
    East Lansing, MI USA
    Posts
    12,937
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Why not store the name in the database and then execute the code on it when you get it out?
    Chris Beasley - I publish content and ecommerce sites.
    Featured Article: Free Comprehensive SEO Guide
    My Guide to Building a Successful Website
    My Blog|My Webmaster Forums

  3. #3
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well if for some reason you need to store it in the database and you need to use it, use:

    PHP Code:
    <?
    $data 
    stripslashes($data);
    $name "Pete";
    eval(
    "$data");
    ?>
    Where $data is the field from the database that contains the code:

    PHP Code:
    echo ($name=="Pete") ? "Yes" "No"
    Remember to addslashes() to that before trying to store it in the db.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  4. #4
    <? echo "Kick me"; ?> petesmc's Avatar
    Join Date
    Nov 2000
    Location
    Hong Kong
    Posts
    1,508
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks allot, that solves allot of problems I thought I'd never over come.

    Another question though. Would the $data have to include <?php and ?>

    -Peter

  5. #5
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    No, it wouldn't.
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference


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
  •