denno020 Posted January 31, 2011 Share Posted January 31, 2011 How can I run php code that is stored in a database? I have my pages created by grabbing the contents of a pageBody mySQL table cell, but some pages require further php to be able to display correctly. For example, I have a players page, which will list all players, and some information about them. The players and information is all saved in a players table in my database (separate to the pages table where pageBody is stored). I use simple php to grab all the players and format all of their information so it can be displayed on the page. This is the flow of information that I would like: User clicks on players page browser loads content page (this is a template page), and grabs the pageid from $_GET browser then reads pages table in database to get the pageBody associated with the pageid The pageBody will contain more php, which will run the players script to retrieve the list, and display Doing it the above way will make it much easier to extend the website to include more types of pages that has to run additional php scripts. The only way I can think of this working is by doing this: user clicks on players page browser loads content page, grabs pageid from $_GET browser checks the pageid for the one associated with players (hard coded into the php script) browser then loads the players.php script instead of going to the database This above way means that I will need to edit the index.php page everytime I add a new list type (example, coaches, volunteers etc). Anyone have any suggestions? I know my question is long, but I was finding it hard to explain it in an easy to understand way, but I'm still not sure if I have :S. Cheers Denno Quote Link to comment https://forums.phpfreaks.com/topic/226203-how-to-run-php-code-that-is-stored-in-a-database/ Share on other sites More sharing options...
trq Posted January 31, 2011 Share Posted January 31, 2011 I'll be honest, I didn't really read your post. I will say this though, storing code in a database is generally a poor design choice. You can look at eval, but be aware, it's not nick named evil for nothing. It can pose quite the security risk allowing users to input and then execute php. There are other options around. Google (PHP Javascript parser). I have used a Javascript parser written in PHP in one of my CMS's to good effect. this allows you to create a macro language (using Javascript syntax) with which you can provide your own safe API instead of allowing PHP itself. I'm at work or I would post a link. Quote Link to comment https://forums.phpfreaks.com/topic/226203-how-to-run-php-code-that-is-stored-in-a-database/#findComment-1167725 Share on other sites More sharing options...
denno020 Posted January 31, 2011 Author Share Posted January 31, 2011 haha I'm not surprised you didn't read it all. Can you suggest another way to get this done? So without storing code in the database? (I think you get the idea of what I'm after?) Cheers Denno Quote Link to comment https://forums.phpfreaks.com/topic/226203-how-to-run-php-code-that-is-stored-in-a-database/#findComment-1167726 Share on other sites More sharing options...
trq Posted January 31, 2011 Share Posted January 31, 2011 Sorry man, I edited my post. You might want to have another read. Quote Link to comment https://forums.phpfreaks.com/topic/226203-how-to-run-php-code-that-is-stored-in-a-database/#findComment-1167727 Share on other sites More sharing options...
denno020 Posted January 31, 2011 Author Share Posted January 31, 2011 ahk just read it. That seems way involved. I'm only creating a website for my local footy club lol. I'll just go with the option that I didn't want to, and if they want another section or something set up, I'll just have to code that in.. Not ideal, but it will do.. Thanks mate. Denno Quote Link to comment https://forums.phpfreaks.com/topic/226203-how-to-run-php-code-that-is-stored-in-a-database/#findComment-1167729 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.