Jump to content

Store, then retrieve / process PHP code (mixed w/ HTML) from mySQL db?


br3nn4n

Recommended Posts

That's a long title, I apologize.

 

I have some code and HTML stored in a cell in my database. Here's the content of the "content" cell:

 

<h1>Pages</h1><hr />
<p><?php $admin->query("SELECT * FROM `pages` WHERE `admin` = '0'");
var_dump($q); ?></p>

 

I googled it and came up with eval(). But in this case, I'm not sure (from a logical viewpoint) how to use it to process the PHP portions of the code.

 

Basically, I'm just storing the entire body of a page in a mySQL table cell, called "content".

 

What would you do? Sorry to leave it so open ended but I can't think. I've thought of maybe doing some regex to find the opening <? and closing ?> tags and then eval anything inside them, but...would that work?

 

As always, any help is hugely appreciated! :D

Maybe to clarify...

 

In a mysql db I have stored some html, along with some PHP in a table cell. When I get that data from the database, I want to have the HTML come out as HTML, and the PHP come out as PHP (ie: be parsed...lol).

Alright, that's not a half bad idea :)

 

Now, my original intention in order to be able to update the pages on my site was to store each in the database (each with its own row) and then edit the "content" cell of any particular page (row) through a web interface. Basically, recreate a text-editor where I can edit the main body of any page.

 

I'm thinking, since I want to keep any editing as simple as possible on myself, that I should make regex functions to do all the adding of echo, escaping quotes, etc. Otherwise, I'm going to have to manually type all that PHP stuff (echo, remembering to escape..etc.) AS WELL AS coding the HTML (which is very easy).

 

I'd like to be able to just code HTML, toss some php in there, maybe add some more HTML, and then have it add any echos and escaping of quotes it needs to, without me having to do it.

 

Am I crazy? be honest ;):P

Okay, good news. I did what you said so now it's just plain php in the table (not even with the <? and ?> tags). Now eval()'ing that works.

 

I'm thinking that in my "simple" page editor I can just place any PHP code inside of <? ?>'s and leave the HTML. Then, have a script add echo()'s and escapes to the HTML parts and simply strip the <? ?> tags of the PHP parts.

 

I really don't know, just trying to get an idea of how a "real" programmer would go about doing this sorta thing

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.