Page 1 of 1

Extracting PHP commands from MySQL

Posted: Tue Dec 09, 2003 9:16 pm
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.

Posted: Tue Dec 09, 2003 11:30 pm
by Nay
You can have the PHP code from the database extracted into a variable, then is then parsed. Look into parse_str().

-Nay

Posted: Wed Dec 10, 2003 2:35 am
by evilcoder
i still cant work it out. That parse_str makes no sense to me.

Posted: Wed Dec 10, 2003 2:44 am
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

Posted: Wed Dec 10, 2003 3:13 am
by evilcoder
yep, i'll try it when i get home, just finished here. Thanks Nay

Posted: Wed Dec 10, 2003 3:36 am
by Nay
All in a days job 8) ;).

*flies away wearing underwear on the outside*

-Nay

Posted: Wed Dec 10, 2003 8:29 am
by aquila125
eval($row['phpcode'])