Jump to content

Archived

This topic is now archived and is closed to further replies.

emexinc

PHP code within mysql database content

Recommended Posts

...is it possible to put php code ( such as a variable ) into a mysql database ( i know this is a yes )...and then be able to pull out that exact code from the database ( i can't get this to work ) and then implement it into a *.*.php file...and then have it conform to whatever that desired variable should be?...i really hope this makes sense as to what i would like to do...thanks for your time...

Share this post


Link to post
Share on other sites
"exact code"? "*.* php file"?

Share this post


Link to post
Share on other sites
exact code = $variable
*.*.php = variable_page.php

...the code is a bunch of lyrics...and there would be php variables mixed into that...so that the user can select what key the song would be shown in...thanks for your help

Share this post


Link to post
Share on other sites
I'm quite confused.

Share this post


Link to post
Share on other sites
...sorry...let me explain this...
...i have a database with 3 columns...( TITLE - AUTHOR - LYRICS_AND_CHORDS )...
* EXAMPLE *...my first row has the following information...
...under TITLE - Beautiful Day
...under AUTHOR - U2
...under LYRICS_AND_CHORDS - <p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;A Bm D G&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; D&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp; A <br>The heart is a bloom, shoots up through the stony ground.</p>

...now if i put all this and then retrieve all these details and input them into variables on a php page, then everything works...but...if i do the following...

<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<?php $_1.'&nbsp;'.$_2 ?>

...when i retrieve this...<?php $_1.'&nbsp;'.$_2 ?> is written exactly as i had put it in...whereas $_1 and $_2 should of been replaced by given variables and then those variables should of been displayed...

...please tell me this makes some sense...

Share this post


Link to post
Share on other sites
Unfortunately, it doesn't -- at least not to me.  You have it working in one case, but now you're trying to use different variables?

Share this post


Link to post
Share on other sites
...i'm making this way too confusing...here it is...i can input php code into a database...such as <?php echo $_1 ?> ...but when I retreive that from the database...it shows up exactly as <?php echo $_1 ?> ...whereas it should of echoed the variable $_1 ( whatever that may be ) ...and that should show up in the source code of that page...but all i see in the source code is <?php echo $_1 ?> ...thanks for continuing to help me with this...

Share this post


Link to post
Share on other sites
Oh... you want to eval() the string that comes back.  That sounds horribly insecure.

Share this post


Link to post
Share on other sites
You are unlucky, because
Your code must not have <? ?> <?php ?>
only php code like
[code]
$code="echo('Hello');";
eval($code); // Hello
[/code]

So you have to use echo for all html and for php use it like you would without the tags and use eval

Share this post


Link to post
Share on other sites
...answer found...thanks guys...simplest fix...i just replaced

echo $row['lyrics_and_chords']

...with...

eval('?>' . $row['lyrics_and_chords'] . '<?php ');

...when i retrieve items from my database...thanks for your time...

Share this post


Link to post
Share on other sites

×

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.