Jump to content


Photo

PHP code within mysql database content


  • Please log in to reply
9 replies to this topic

#1 emexinc

emexinc
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 13 August 2006 - 06:35 AM

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

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 13 August 2006 - 03:04 PM

"exact code"? "*.* php file"?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 emexinc

emexinc
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 13 August 2006 - 09:09 PM

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

#4 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 14 August 2006 - 05:20 AM

I'm quite confused.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#5 emexinc

emexinc
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 14 August 2006 - 06:17 AM

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

#6 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 14 August 2006 - 02:55 PM

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?
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#7 emexinc

emexinc
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 15 August 2006 - 04:13 AM

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

#8 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 15 August 2006 - 05:03 AM

Oh... you want to eval() the string that comes back.  That sounds horribly insecure.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#9 Chetan

Chetan
  • Members
  • PipPipPip
  • Advanced Member
  • 162 posts
  • LocationIndia

Posted 15 August 2006 - 06:01 AM

You are unlucky, because
Your code must not have <? ?> <?php ?>
only php code like
$code="echo('Hello');";
eval($code); // Hello

So you have to use echo for all html and for php use it like you would without the tags and use eval
I am a PHP Guru, ask me questions if you want to

#10 emexinc

emexinc
  • Members
  • PipPipPip
  • Advanced Member
  • 34 posts

Posted 16 August 2006 - 05:18 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users