• 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)
  • Thread Starter ddefelicis

    (@ddefelicis)

    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

    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

    (@ddefelicis)

    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.

    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 class.

    On top of that you really should extract this code out of your post, and turn it into a shortcode 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

    (@ddefelicis)

    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.