• Resolved freshifreshy

    (@freshifreshy)


    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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • 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?

    Thread Starter freshifreshy

    (@freshifreshy)

    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!

    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 —

    https://codex.www.ads-software.com/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.

    Thread Starter freshifreshy

    (@freshifreshy)

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

    https://pastebin.com/bpAbkCuq

    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.

    Thread Starter freshifreshy

    (@freshifreshy)

    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!

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Headers Already Sent Problem…’ is closed to new replies.