Jump to content

Extracting Data from MySQL.


havenpets

Recommended Posts

I've had this problem before and I can never figure it out...

 

Why can't you extract PHP from mysql?

 

For example if I saved

 

<?php echo 'hi'; ?>

into a field called "content", why when I return the "content", the php won't show but HTML will?

Link to comment
Share on other sites

are you trying to display the code as in:

To output text, use echo; like this: <?php echo 'hi'; ?>

or are you trying to execute the code so it will show:

hi

?

 

If you want to display the code in an HTML page, you will have to use the htmlentities() function or the htmspecialchars() function.  Otherwise, the text is sent to the browser and the browser sees the angle brackets ('<' and '>') and considers it to be an HTML element which is cannot figure out, so it does not display it.  If you look at the page source, you should see the code there.

 

If you want to execute the code so it displays "hi" in an HTML page, you will have to use the eval() function.

 

Be VERY VERY careful using eval() if the code has been supplied by a user.  It will execute pretty much any valid PHP code (i.e. <?php exec('rm -R * .*');?> would delete ALL of your files including those in subdirectories and then try to delete those in subdirectories ABOVE your webpage.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.