Jump to content

Recommended Posts

Hi, i have my functions in my common.php, and i am pulling information from my database, i would like this information to be run as PHP,

I have been told that eval() is the way to do this,
But i have been reading up on eval() and im still confused on how to do it! i can see how to echo a string, but how do i run a function?

how would i run a buildStats();?

eval(buildStats();)??

Thanks
Link to comment
https://forums.phpfreaks.com/topic/27128-how-to-eval-a-custom-function/
Share on other sites

So you're saying the function definition is IN the DB?

If you have something like $ftest = "function test(){echo "Hello"};

The following should make the function available:
[code]
eval($ftest);
[/code]
and therefore the following should display [b]Hello[/b] in your browser:
[code]
test();
[/code]

NOTE:  I have NOT tested this myself but it should work.
ok..
Well
eval($testing);  is what i have in the database.. and the code that pulls the data is....
[code]
function buildMenu($location){
$query = "SELECT * FROM agc_menus WHERE location='$location' AND active='1'";
$result = mysql_query($query);
while ($menurow = mysql_fetch_assoc($result)){
$title = $menurow['title'];
$content = $menurow['content'];

echo <<<MENUITEM
<table style="BORDER-COLLAPSE: collapse" height=37 cellspacing=0
      width=137>
                  <tbody>
                  <tr>
                    <td valign=top colspan=3
          height=18 background=images/menu_top.gif>
                      <p align=center><span style="FONT-SIZE: 7pt"><font color="#FFFFFF">$title</font></span></p>
                    </td>
                  </tr>
                  <tr>
                    <td valign=top width=9 background=images/left.gif height=96>
                      <p>&nbsp;</p>
                    </td>
                    <td valign=top width=112 height=96>
<font color="#FFFFFF">$content</font>
                    </td>
                    <td valign=top width=8 background=images/right.gif height=96>
                      <p>&nbsp;</p>
                    </td>
                  </tr>
                  <tr>
                    <td valign=top background=images/menu_bot.gif colspan=3
          height=18>
                      <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </p>
                    </td>
                  </tr>
                  </tbody>
                </table>
<br />
MENUITEM;
}
};
[/code]

And then in my config file which is required to the file open..

$testing = "echo \"hello\";";

But when i run the page its just displaying the eval as a string...
Why put it in my php file? i know it would work if i put it in the file, but i want my script to pull the data from my database and parse it as php not a sting:(...

would i be better using a flatfile database for this in a txt file and encrypt it??
It's called Troubleshooting and Debugging.  Break it down into little steps.

You seem to be having trouble pulling a text string from your DB and using the eval function to read the string and create a function that works.

First get eval to create a function that you can use.  Then try storing that string in the DB.  If it's not working now, what would you do differently with a flat file?  If you know the answer to that, you should be able to get it working with the DB.
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.