Welcome to WebmasterWorld Guest from 54.162.154.91

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Storing PHP into a MySQL database

trying to retrieve the php code on a database

     
11:43 pm on Jan 7, 2009 (gmt 0)

New User

5+ Year Member

joined:Jan 7, 2009
posts: 2
votes: 0


I'm using Ajax to make a connection to the server, and ofcourse it should interact with my php script, and the php script pulls info from a database.

However, it seems that the only info I can pull is either javascript or html. The php won't parse. when I try to retrieve the php stored on my table it doesn't do anything. But it works very well for javascript or html.

To make things more clearer: I'm using Ajax to load info into an empty div. I have about 6 divs that form my layout and they're all saved under a .php extension. Even if I remove the Ajax, the PHP is not being executed, while HTML or Javascript under the same circumstances runs well. I changed the table type/collation to utf general hoping it would make it work.

Help please.

1:39 am on Jan 8, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 5, 2008
posts:112
votes: 0


You can't pull a server-side language from a database as far as I know, because if I'm not mistaken, you're probably echoing it. Anything you echo won't be compiled by the server, it will just be outputted to the web page. If you want to compile external PHP, you'll probably have to use include() and use a file, not database.
5:09 pm on Jan 8, 2009 (gmt 0)

Administrator

WebmasterWorld Administrator coopster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:July 31, 2003
posts:12548
votes: 2


You could execute PHP code from a database if you use the eval [php.net] function. However, do so with extreme caution and if it was user-supplied content there is absolutely no way I would even consider using this function. I would never use eval on user-supplied data. You would have to be mad to consider it.
5:21 pm on Jan 8, 2009 (gmt 0)

Junior Member

10+ Year Member

joined:Nov 22, 2004
posts:133
votes: 0


eval( )
man those php guys thought of EVERYTHING :-)
7:27 pm on Jan 8, 2009 (gmt 0)

Junior Member

5+ Year Member

joined:Jan 5, 2008
posts:112
votes: 0


If you had:

$code = "<html>
<head>
<title>Title</title>
</head>
<body>
<?=date()?>
</body>
</html>";

eval($code);

Would that print out correctly?

8:52 pm on Jan 8, 2009 (gmt 0)

New User

5+ Year Member

joined:Jan 7, 2009
posts: 2
votes: 0


Thanks for all the input! Ya what I was trying to do was to create a guestbook , using Ajax and php, and when the user clicks submit the guestbook.php will send the info to a table. All this would've been in local page. But because I couldn't store php I had to remove the php from the database and put it in .php file. but when the user clicks submit it would take them to that php page, therefore breaking the Ajax "feel" I was looking for. I'll try the eval and see how that works. I'll get back to you with the results.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members