Closed Thread Icon

Topic awaiting preservation: calling PHP from a mySQL database (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=26261" title="Pages that link to Topic awaiting preservation: calling PHP from a mySQL database (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: calling PHP from a mySQL database <span class="small">(Page 1 of 1)</span>\

 
dade
Nervous Wreck (II) Inmate

From: Kansas, just this side of the rainbow
Insane since: Sep 2004

posted posted 07-17-2005 04:50

This really burns my chaps, but I can store PHP in a mySQL table and retrieve it with everything working fine...as long as the PHP goes into the HEAD tag in a HTML page. HOWEVER, when I retrieve PHP from a mySQL table and place it in the BODY tag of a HTML page, it simply places in the file without parsing it.

Is there a way to get this to work?

Thank you,

Dustin

This patient is ready for his medication!

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 07-17-2005 05:16

can you be more specific?

Give an example of the code in question, and the way it's stored, called, etc. Is it wrapped in <? ?>?

dade
Nervous Wreck (II) Inmate

From: Kansas, just this side of the rainbow
Insane since: Sep 2004

posted posted 07-17-2005 05:33

Actually it is a simple include code (calling an external PHP file):

code:
<?php include( 'includes/catalog_menu.php'); ?>



It is stored in a mySQL table in a TEXT field with other HTML code. Basically, I have a body field that is called that contains HTML and this PHP line.

Example:

code:
<body>
  <table>
    <tr>
      <td>
        some text.<br>
        <?php include( 'includes/catalog_menu.php'); ?>
      </td>
    </tr>
  </table>
</body>



Like I said, I have a field for the header as well, and it works fine. Any suggestions or alternatives?

Thank you,

Dustin

P.S. and it always is wrapped in <?php, ?> as I don't have <?, ?> turned on.

This patient is ready for his medication!

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 07-17-2005 08:50

At first guess i would say its to do with the ' marks. I'm also assuming you are getting the database entries using PHP.

So take a look at addslashes() and removeslashes() , it depends on your phpini settings. Normall when you add to the database it will addslashes and when you take from the database it will remove them. So... when you manually put something in the database without slashes it might remove the ' marks etc when you retrieve it or something.

I'm assuming also that you are editing the database directly (phpadmin or something) - try putting slashes infront of your quotes see if it makes a diff.

<?php include( \'includes/catalog_menu.php\'); ?>

This might not be the problem, but at first glance im guessing its something to do with this so have a play around.

zavaboy
Bipolar (III) Inmate

From: f(x)
Insane since: Jun 2004

posted posted 07-17-2005 10:45

I think I know what you want... leme know if I'm correct.

You have PHP code in a MySQL table and want to get it and execute it.

For example you have this in your database table:

code:
<a href="some_page.php"><?php echo 'hello'; ?></a>



You want it to give the browser this:

code:
<a href="some_page.php">hello</a>



But it comes out like this:

code:
<a href="some_page.php"><?php echo 'hello'; ?></a>



My solution would be: ($php2print contains what you got from the database)

code:
eval('?>'.$php2print.'<?php');



This will basically print any HTML and execute any PHP within.
Is that what your looking for?

CPrompt
Maniac (V) Inmate

From: there...no..there.....
Insane since: May 2001

posted posted 07-22-2005 03:50

a little off topic, but what is the advantage of storing an includes statement in a database?

Later,

C:\

H][RO
Bipolar (III) Inmate

From: Australia
Insane since: Oct 2002

posted posted 07-22-2005 07:12

Could be generating static pages maybe?

Good point though, interested to find out also

« BackwardsOnwards »

Show Forum Drop Down Menu