pascale Posted November 10, 2010 Share Posted November 10, 2010 I am working on a kind of CMS for my own website which no one else will be using but me as a way of improving my php skills, and am having problems with retrieving data from the database that holds both text and php code. I have searched the web and found that i should be using eval() for the code to be executed before it is send to the browser but cannot get it to work and can't find my mistake(s). the php code will always be the same, and is supposed to retrieve the id number of a page to use in a link (and works fine when tested by loading the code directly without retrieving it from the database) this is an example of data stored in the database The <a href="page_builder.php?id=<?php echo $page->id('mines_DwarvenMines') ?>">Dwarven Mines</a> have a great selection of Ores,... Of course when I leave it like this, hovering over the link in my page will show exactly that and lead to nowhere localhost/page_builder.php?id=<?php echo $page->id('mines_DwarvenMines') ?> Most of these links appear in tips given at the end of the page and are processed as followed $questtips = $quest->getQuestTips(); $tips = ""; if ($questtips == "none") { $tips = "/"; } else { foreach($questtips as $tip) { $tips .= "<li>"; $tips .= $tip->getTip(); $tips .= "</li>"; } } and finally put on screen by the presentation layer as followed <h2>Tips & Extra Info</h2> <div class="tipsList"> <ul> <?php echo $tips ?> </ul> </div> I have tried all sorts to get the code to be executed when retrieved from the database before being send to the browser so that this particular link would say "localhost/page_builder.php?id=57" but I cannot get it to work, though I suspect it is fairly easy. I suspect I would have to store the data in a different format in the database? And how exactly do I use the eval() function in my case? Could someone please adjust my code so that it does work? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/218270-storing-and-retrieving-php-code-in-mysql-database/ Share on other sites More sharing options...
trq Posted November 10, 2010 Share Posted November 10, 2010 PHP is not meant to be stored within a database, and while it is possible, I would suggest it is a poor design choice. Quote Link to comment https://forums.phpfreaks.com/topic/218270-storing-and-retrieving-php-code-in-mysql-database/#findComment-1132572 Share on other sites More sharing options...
pascale Posted November 10, 2010 Author Share Posted November 10, 2010 well if it is not to be done this way, can you then tell how to do it the 'proper way' Quote Link to comment https://forums.phpfreaks.com/topic/218270-storing-and-retrieving-php-code-in-mysql-database/#findComment-1132575 Share on other sites More sharing options...
trq Posted November 10, 2010 Share Posted November 10, 2010 Instead of your users needing to remember to type <?php echo $page->id('mines_DwarvenMines') ?> to have a simple id displayed within there link, your editor should have a mechanism for supplying these id's from a drop down or some such other UI element. Quote Link to comment https://forums.phpfreaks.com/topic/218270-storing-and-retrieving-php-code-in-mysql-database/#findComment-1132578 Share on other sites More sharing options...
pascale Posted November 10, 2010 Author Share Posted November 10, 2010 i do understand what you are saying, but as i mention in my question, this is purely for my own use, there are no users on the site, nor will there ever be. I am only a beginning php programmer and have most of it working. I could try and write the code to do what you suggest, but as it is only me who will ever use it, I want to concentrate on other aspects of it for now and wanted to solve it using the eval() function but without success. If you do know the answer, could you please help me out? Quote Link to comment https://forums.phpfreaks.com/topic/218270-storing-and-retrieving-php-code-in-mysql-database/#findComment-1132580 Share on other sites More sharing options...
trq Posted November 10, 2010 Share Posted November 10, 2010 Ive given you the answer. Eval is almost always a poor design choice, what else do you want me to say? I would never recommend the path your trying to go down. Quote Link to comment https://forums.phpfreaks.com/topic/218270-storing-and-retrieving-php-code-in-mysql-database/#findComment-1132581 Share on other sites More sharing options...
pascale Posted November 10, 2010 Author Share Posted November 10, 2010 ok Quote Link to comment https://forums.phpfreaks.com/topic/218270-storing-and-retrieving-php-code-in-mysql-database/#findComment-1132582 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.