Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Mar 2010
    Posts
    19
    Thanks
    0
    Thanked 1 Time in 1 Post

    Include some outside code in Wordpress

    Hello!

    I would like to know how can I include a piece of external code in the wordprpress.

    I tried to add my code in the footer.php (wp-content/themes) but whit no suces..

    This is the code that i need to add:

    PHP Code:
    <?php
    $site_id 
    "48";
    include(
    'banner.php');
    ?>
    But when I try to run my blog I got several MySQL errors.

    banner.php have it's own class that call an external MySQL, and I can't iframe this because I need to capture referer...

    Some one have some idea?

  • #2
    Regular Coder xconspirisist's Avatar
    Join Date
    Jun 2006
    Location
    Great Britain.
    Posts
    138
    Thanks
    1
    Thanked 6 Times in 6 Posts
    Could you be more descriptive as to your problem, or error message?

    The code that you have there is correct to include a local php file.
    If I have been helpful, use the "thank" button - It makes me happy!

    xconspirisist.co.uk - homepage of my online alias
    technowax.net - a community for people interested in all forms of modern technology.

  • #3
    New Coder
    Join Date
    Mar 2010
    Posts
    19
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by xconspirisist View Post
    Could you be more descriptive as to your problem, or error message?

    The code that you have there is correct to include a local php file.
    I think the problem is that my script banner.php calls other MySQL connection, and I don't know why I cant call other MySQL connection...

    The error is very simple: "Error: Can't connect to localhost"

    But when I iframe test.php that have this code included, the code runs well...

  • #4
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    If your connecting to a different database you need to close the connection thats open at the moment before you can do that.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #5
    New Coder
    Join Date
    Mar 2010
    Posts
    19
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by DJCMBear View Post
    If your connecting to a different database you need to close the connection thats open at the moment before you can do that.
    Yeah, I'm pretty sure about this. But how can I close the main Wordpress MySQL connection if it will need it to execure the other part of the code?

  • #6
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    find out where they open then db, like sometimes people use $con = mysql_query(""); all you need to do then is put mysql_close($con); just before your code but you have to reopen the other db after you have finished using yours or WP wont work.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #7
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Quote Originally Posted by DJCMBear View Post
    If your connecting to a different database you need to close the connection thats open at the moment before you can do that.
    Are you sure? I don't think so.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #8
    New Coder
    Join Date
    Mar 2010
    Posts
    19
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by DJCMBear View Post
    find out where they open then db, like sometimes people use $con = mysql_query(""); all you need to do then is put mysql_close($con); just before your code but you have to reopen the other db after you have finished using yours or WP wont work.
    Are u sure that your idea will work?

    Are u talking about this?
    PHP Code:
    $wp->dbcloseclass();
    include(
    'mycode.php');
    $wp->dbopenclass(); 
    I'm trying the Wordpress suport forum, but no one replyed to me yet...

  • #9
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    well it looks ok but what you was trying to do was access a table in a different db but because you didnt close the other one php was looking inside the WP db not yours.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #10
    New Coder
    Join Date
    Mar 2010
    Posts
    19
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by DJCMBear View Post
    well it looks ok but what you was trying to do was access a table in a different db but because you didnt close the other one php was looking inside the WP db not yours.
    Yeah, I think so..

    As i said, I'm tryng the wordpress suport forum to know what's the class to close and reopen the connection, after that is aswered I'll try out your idea.

  • #11
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    Quote Originally Posted by TripBR View Post
    Yeah, I think so..

    As i said, I'm tryng the wordpress suport forum to know what's the class to close and reopen the connection, after that is aswered I'll try out your idea.
    arite well the WP forum is the best place to ask because they are the people who made it and would know it back to front lol.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #12
    New Coder
    Join Date
    Mar 2010
    Posts
    19
    Thanks
    0
    Thanked 1 Time in 1 Post
    Quote Originally Posted by DJCMBear View Post
    arite well the WP forum is the best place to ask because they are the people who made it and would know it back to front lol.
    bit off topic: i know that there is the best place to ask about this, but I'm on it from 2 days now, and no aswers...

  • #13
    Senior Coder DJCMBear's Avatar
    Join Date
    Mar 2010
    Location
    United Kindom
    Posts
    1,173
    Thanks
    14
    Thanked 136 Times in 136 Posts
    well they are a populare system so they do have many people to contact. But 2 days is abit to long really.
    Official BinPress hand picked coder.
    For anyone worried about SQL injection go have a look at my small yet powerful script here.
    Go Pledge for Light Table, if it hit's $300,000 Python and other languages will get added.
    I am 1 of 65,608 people to get a Pebble Watch :P

  • #14
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The error is very simple: "Error: Can't connect to localhost"
    The error might be very simple, but error checks that you've added in your code looks very poor. Could you post the code in your banner.php here?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #15
    New Coder
    Join Date
    Apr 2010
    Posts
    38
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Smile

    http://codex.wordpress.org/Pages#Page_Templates

    You may create a custom page in wordpress. Use include page plugin, if you do not want to create a word press plugin for your banner application.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •