Title: Php problem in wp pages
Last modified: August 21, 2016

---

# Php problem in wp pages

 *  [ddefelicis](https://wordpress.org/support/users/ddefelicis/)
 * (@ddefelicis)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/php-problem-in-wp-pages/)
 * I”ve activated a plugin to’ use php code inside the wp pages.
    It works but if
   I need to insert HTML code inside the [ php] [/php] code using the statement 
   Echo < HTML code>;
 * The expression between < and > is not considered.
 * This is a problem if I want to’ fill a listbox from a mysql database
 * thanks

Viewing 6 replies - 1 through 6 (of 6 total)

 *  [elisabetha](https://wordpress.org/support/users/elisabetha/)
 * (@elisabetha)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/php-problem-in-wp-pages/#post-4809618)
 * Maybe this helps:
    [http://stackoverflow.com/questions/1100354/how-can-i-echo-html-in-php](http://stackoverflow.com/questions/1100354/how-can-i-echo-html-in-php)
 *  Thread Starter [ddefelicis](https://wordpress.org/support/users/ddefelicis/)
 * (@ddefelicis)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/php-problem-in-wp-pages/#post-4809642)
 * Yes i’ve made what you suggest as you can see in my original question but in 
   a wordpress page the HTML code after the < tag is erased.
 * E.g.
    [php] Echo “<hello word>”; [\php]
 * Produce nothing
 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/php-problem-in-wp-pages/#post-4809654)
 * If that’s exactly what you’re trying to use, then it’s never going to work. What
   you’re printing out from your PHP code is a tag, and in invalid tag at that. 
   What you’d need is something more like this…
 *     ```
       [php]
       echo "<p>Hello World</p>";
       [/php]
       ```
   
 *  Thread Starter [ddefelicis](https://wordpress.org/support/users/ddefelicis/)
 * (@ddefelicis)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/php-problem-in-wp-pages/#post-4809673)
 * Sorry I’ve previously semplified too much my problem:
 * I want to fill a listbox with mySQL data in a WP page (I’m writing an HTML form
   data INPUT) and I need to use PHP.
    I’ve activated the plugin “Allow PHP in Posts
   and Pages”.
 * To fill my listbox I used this code (copied by PHP manual):
 * <form action=’processform.php’ method=’POST’>
    [php] … … <select name=’petType’
   >\n”; while ($row = mysqli_fetch_assoc($result)) { extract($row); echo “<option
   value=’$petType’>$petType\n”; } echo “</select>\n”; … … [/php]
 * the statements ” echo “<option value=’$petType’>$petType\n”; “
 * it’s not considered by WP when I update the page.
 *  [catacaustic](https://wordpress.org/support/users/catacaustic/)
 * (@catacaustic)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/php-problem-in-wp-pages/#post-4809695)
 * OK… You should give that osrt of info before hand so we know waht we’re really
   dealing with, but it’s OK.
 * So tell me, what does it actually output? I don’t mean what do you see, I mean
   what is the final HTML code that you see on your page when you use that?
 * To be honest, you’re really not doing it the right way. If you’re going to do
   this correctly you should ditch your database call and change that to use the
   [$wpdb](https://codex.wordpress.org/Class_Reference/wpdb) class.
 * On top of that you really should extract this code out of your post, and turn
   it into a [shortcode](http://codex.wordpress.org/Shortcode_API) so that it can
   be used there without that plugin, and it can be used somewhere else if it’s 
   needed as well.
 * And as a closing thought, all HTML tags should be closed, not left open like 
   you’ve done with the option tag there. It’s not stricyl required depending on
   your doc type, but i fyou always stick to closing tags all th etime you’ll find
   a whole lot better results in the future.
 *  Thread Starter [ddefelicis](https://wordpress.org/support/users/ddefelicis/)
 * (@ddefelicis)
 * [12 years, 1 month ago](https://wordpress.org/support/topic/php-problem-in-wp-pages/#post-4809709)
 * Thank you for your patience, I’m a beginner.
 * The plugin activated is “allow php code in posts and pages”.
 * I’d like to fill a listbox with database and I wrote the following code that 
   works without problem in a php file loaded as page template but edited inside
   the WP page I obtain an empty listbox because (according to me) the html code
   after echo it’s not considered.
 * <form action=’processform.php’ method=’POST’>
    <select name=’Category’> [php]
   $Conn = mysql_connect(“localhost”, “root”, “”); if (!$Conn) { die(‘Could not 
   connect: ‘ . mysql_error()); } mysql_select_db(“dati”,$Conn); $query = “SELECT
   Category FROM Dati.prodotti”; $result=mysql_query($query,$Conn); $row = mysqli_fetch_assoc(
   $result); while ($row = mysql_fetch_assoc($result)) { echo “<option value=”.$
   row[‘Category’].”>”.$row[‘Category’].”</option>”; } [/php] </SELECT> </form>

Viewing 6 replies - 1 through 6 (of 6 total)

The topic ‘Php problem in wp pages’ is closed to new replies.

## Tags

 * [php](https://wordpress.org/support/topic-tag/php/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 6 replies
 * 3 participants
 * Last reply from: [ddefelicis](https://wordpress.org/support/users/ddefelicis/)
 * Last activity: [12 years, 1 month ago](https://wordpress.org/support/topic/php-problem-in-wp-pages/#post-4809709)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
