WordPress.org

Ready to get started?Download WordPress

Forums

How do I add a PHP script on a page? (23 posts)

  1. smithy285
    Member
    Posted 2 years ago #

    Hello,
    I want to add a PHP script onto one of my WordPress pages.
    The only problem is that it shows the code but nothing happens!
    I tired installing a plugin called: Exec-PHP but there was no change.
    Here is the code:

    <?php
    $sql_host = ""; //host adress
    $sql_user = ""; //username
    $sql_pass = ""; //password
    $sql_database = ""; //database name
    mysql_connect($sql_host, $sql_user, $sql_pass) or die(mysql_error());
    mysql_select_db($sql_database) or die(mysql_error());
    ?>

    When I put it on my page I fill out the SQL bit but I don't want to post it here unless I have to.
    Please can you help me! A Tutorial on how to fix/solve this would be amazing!

  2. deepbevel
    Member
    Posted 2 years ago #

    you say it shows the code, do you mean literally? or is it outputting anything as expected?

  3. smithy285
    Member
    Posted 2 years ago #

    It shows the raw code nothing else e.g not what it is supposed to.

  4. deepbevel
    Member
    Posted 2 years ago #

    looks like it could be the way you're filling the SQL values, I tried it as is and I get no raw code, but of course no output either.

  5. smithy285
    Member
    Posted 2 years ago #

    I will try again!

  6. smithy285
    Member
    Posted 2 years ago #

    Read below

  7. smithy285
    Member
    Posted 2 years ago #

  8. deepbevel
    Member
    Posted 2 years ago #

    that's a log in url, which page on your site is showing the raw code? post that lnk.

  9. smithy285
    Member
    Posted 2 years ago #

  10. hauntingreview
    Member
    Posted 2 years ago #

    So you are using EXEC PHP ? Dumb question, are you adding it in VISUAL or HTML ?

  11. deepbevel
    Member
    Posted 2 years ago #

    yeah that's weird, never seen that unless it was a syntax error. It's as if that's how it's supposed to output. Do you know what the output should look like? example?

  12. deepbevel
    Member
    Posted 2 years ago #

    ah, hauntingreview, that's actually a great question. I'm betting that's it!

  13. smithy285
    Member
    Posted 2 years ago #

    Sorry mod but how can I get people to answer it?

    I tried it in Visual and HTML I will add both on the page again

    Here is what it is meant to look like:
    http://hg.mooshroom.net/status.php?ip=hg.mooshroom.net

  14. hauntingreview
    Member
    Posted 2 years ago #

    Thanks deepbevel. I just tested on my development site and it works, if you add the code in the HTML editor and not the visual.

    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'pilecrap'@'localhost' (using password: NO) in /home/pilecrap/public_html/dev/wp-content/plugins/exec-php/includes/runtime.php(42) : eval()'d code on line 6

  15. hauntingreview
    Member
    Posted 2 years ago #

    smithy, in that case I would recommend you look at your theme or other existing plugins that may simply be stripping out the code. My development site uses Twenty Eleven and it at least attempts to use the code with EXEC-PHP.

  16. deepbevel
    Member
    Posted 2 years ago #

    this code needs to go in a php file, (page.php, post.php, ect.) not in the page-post editor. unless exec php a plugin which should allow that? maybe it's got issues/conflicts? You might try it in a php template.

  17. hauntingreview
    Member
    Posted 2 years ago #

    EXEC PHP allows you to run PHP code in posts, pages, widgets, ect... I've used it several times in the past, once I even implemented a costum Case Log script I wrote into my PHP site using it.

    It should be working and if it isn't then there's something on his end striping the code.

  18. smithy285
    Member
    Posted 2 years ago #

    How do I do that @deepbevel? I use a theme call LeetPress

  19. cjc1867
    Member
    Posted 2 years ago #

    Have you followed the instructions in the documentation? the visual editor has to be disabled and a user has to be assigned to use it.

    they ask you to confirm it working by inserting this piece of code
    <?php echo "This is the Exec-PHP 'Hello World'"; ?>

    I followed the instructions and have it working but not your database connection code.

  20. deepbevel
    Member
    Posted 2 years ago #

    hauntingreview is correct, but If your code can suit your purpose just the same in a template, you can insert it in page.php or post.php, probably outside the loop. that means

    after
    "if have posts"

    but before
    "while have posts"

    or, before

    "if have posts"

    or after

    "endwhile" or "endif"

  21. deepbevel
    Member
    Posted 2 years ago #

    Better if you can get exec php working, you won't have to mess with any css.

  22. smithy285
    Member
    Posted 2 years ago #

    @cjc1867 I did what you said and it seems to of done the trick! well half of it, like you said there seems to be something wrong with my database and tips on how to sort this out? for the address do I put ip:port ?

  23. smithy285
    Member
    Posted 2 years ago #

    Also here are the instructions for the code if there helps you guys

    Your page has to have the ending "*.php"
    You have to allow access to the MySQL database from other IPs the MC server and the website are not running on the same host.
    The database has to be accessed by the server and by the website. Make sure the database allows this (normally it can just be accessed locally). You might want to contact your hoster before going on.
    Do not change any of this code, exept for the first variables to set the MySQL connection.

    First you have to put the following code a the top of your web page. (You only have to put the following code once on your page.)

    Thank you so much for helping me as I am a total noob at this.

Topic Closed

This topic has been closed to new replies.

About this Topic