WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Headers Already Sent Problem... (7 posts)

  1. freshifreshy
    Member
    Posted 2 years ago #

    I'm trying to run the following code to export some mysql data as an CSV/excel file, but I keep getting a "Cannot modify header information - headers already sent" error.

    I've checked the offending file (wp-admin/menu-header.php:114). It's a core WP file and it seems fine to me. No extra spaces at beginning or end. I even tried re-installing it. Can anyone take a look at this and let me know what I could try?

    [Code moderated as per the Forum Rules. Please use the pastebin]

    Thank you!

  2. tasty.donuts
    Member
    Posted 2 years ago #

    Sounds like the WP file is fine because it's already sending the headers to communicate with that table in the database. If it's mission critical instead of untangling all this may want to set up another Database or table to hold this info?

  3. freshifreshy
    Member
    Posted 2 years ago #

    Good to know that's an option. Although I'd be curious to know what a solution might look like that keeps the data where it is... Thank you!

  4. tasty.donuts
    Member
    Posted 2 years ago #

    I did some looking and it looks like this is possible, however I'm kind of in the dark since your code was removed and because I haven't dealt with this issue yet myself --

    http://codex.wordpress.org/Class_Reference/wpdb

    Seems like you may have to play with where the PHP lives and get into how to append or change the headers being sent for your particular file.

  5. freshifreshy
    Member
    Posted 2 years ago #

    Here's the code I'm working with in case you can offer any insight. Thanks again!

    http://pastebin.com/bpAbkCuq

  6. tasty.donuts
    Member
    Posted 2 years ago #

    Yeah I think you're going to have a really hard time unless you use that wpdb object to query the DB, you're not using it in your example so my guess is you're trying to query the database when WP has already established a connection to it. I would imagine that if you implement the wpdb object correctly according to the documentation it will be "in the loop" so to speak and therefore I would start over with whatever data you're trying to pass it from there.

  7. freshifreshy
    Member
    Posted 2 years ago #

    Thanks tasty.donuts,

    I tried rewriting the code to use the wpdb object, but it started to feel cumbersome.

    Instead, I avoided the wpdb object by opening a new connection to my WP database using the standard method, which solved the headers warning.

    Thanks again!

Topic Closed

This topic has been closed to new replies.

About this Topic