Extracting PHP commands from MySQL

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Extracting PHP commands from MySQL

Post by evilcoder »

hey there.

I have a database field that contains php code. I'd like to know why when on my mainpage that extracts this database entry that the command isnt executed?

Is there a way to pre-parse the code so that it does execute, or is code in a database entry useless?

thanks guys.
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

You can have the PHP code from the database extracted into a variable, then is then parsed. Look into parse_str().

-Nay
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

i still cant work it out. That parse_str makes no sense to me.
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Okay, say this code is in the database:

Code: Select all

$name = "nay";
Okay, so PHP just looks at it like:

Code: Select all

$rows['the_row'] = "\$name = "nay"";
So it's "unparsed". So you can parse_str($rows['the_row']), and then you can echo $name and nay would be printed out.

Get me? :)

-Nay
evilcoder
Forum Contributor
Posts: 345
Joined: Tue Dec 17, 2002 5:37 am
Location: Sydney, Australia

Post by evilcoder »

yep, i'll try it when i get home, just finished here. Thanks Nay
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

All in a days job 8) ;).

*flies away wearing underwear on the outside*

-Nay
User avatar
aquila125
Forum Commoner
Posts: 96
Joined: Tue Dec 09, 2003 10:39 am
Location: Belgium

Post by aquila125 »

eval($row['phpcode'])
Post Reply