Jump to content

storing and retrieving php code in mysql database


pascale

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.