SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Jul 2013
    Location
    Sugarland, TX
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How can I store PHP code inside of a MySql table?

    Hi
    I'm wondering, if anybody can help inserting php code in mysql table via HTML form fields?

    Thanks

  2. #2
    Barefoot on the Moon! silver trophy Force Flow's Avatar
    Join Date
    Jul 2003
    Location
    Northeastern USA
    Posts
    4,615
    Mentioned
    56 Post(s)
    Tagged
    1 Thread(s)
    Can you give an example of what you're trying to accomplish?

    Databases are intended to store data, not blocks of code.
    Visit The Blog | Follow On Twitter
    301tool 1.1.5 - URL redirector & shortener (PHP/MySQL)
    Can be hosted on and utilize your own domain

  3. #3
    SitePoint Member
    Join Date
    Jul 2013
    Location
    Sugarland, TX
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your reply ..


    For example: A value is defined in php like "define("YEAR",date("Y"));"

    Now, I'd like this "YEAR" value to be printed on site after its being add into site DB through back-end admin panel using html form fields such as textfield or textarea.

    For Example:

    If posted value of a textfield is like "Sale ".YEAR.", on Shoes & Sandals at Crocs.com .."

    >> should be printed as "Sale 2013, on Shoes & Sandals at Crocs.com .."

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,228
    Mentioned
    194 Post(s)
    Tagged
    2 Thread(s)
    Hi M.King, welcome to the forums.

    Sorry, but I'm confused by your example.

    Why not just call date() in your code instead of calling the database for a CONSTANT value? (wouldn't it be better as a variable?)

    I'm wondering if you're trying to bang something into doing something that could be done in a better way.

    Storing code in a database could be risky business as running it would probably use eval() IMHO not worth doing this way, if not for security reasons, to reduce resource use.

  5. #5
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,182
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    If you are merely dealing with simple string replacement I would recommend using a token system. You could implement something as simple as {DATE} than use str_replace() to replace the date within the user supplied content held in the database. Of course you could expand this to be as complex as necessary to achieve the given requirements of your specific requirements so far as to creating a language on top of php. However, I would recommend against this only allowing simple token replacement.
    The only code I hate more than my own is everyone else's.


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
  •