-2

Working on this script but I am having header already sent troubles on lines that allow you to download the CSV.

http://pastebin.com/6bTjBri5

An error shows:

Warning: Cannot modify header information - headers already sent by (output started at /home/briancqc/public_html/config.php:5) in /home/briancqc/public_html/export.php on line 29

Warning: Cannot modify header information - headers already sent by (output started at /home/briancqc/public_html/config.php:5) in /home/briancqc/public_html/export.php on line 30

Warning: Cannot modify header information - headers already sent by (output started at /home/briancqc/public_html/config.php:5) in /home/briancqc/public_html/export.php on line 31

Where would I add a <br> so after every row a new line starts?

How it looks right now:

It all goes in a constant line for the export of the rows.

Community
  • 1
  • 1
Brian Cherdak
  • 105
  • 2
  • 16
  • You're starting your headers here: /home/briancqc/public_html/config.php:5 and that's conflicting with what you're trying to send here /home/briancqc/public_html/export.php:29-31 – chrislondon Jun 29 '13 at 20:02
  • What does line 5 on /home/briancqc/public_html/config.php say? – chrislondon Jun 29 '13 at 20:03
  • Don't put php end tags at the end of a file, because as martain said even a blank line will cause output – Kris Jun 29 '13 at 20:13
  • That seemed to work, but some things didn't, when I downloaded the file, it all is messed up and isn't separated into separate columns and rows. Here is how it looks: http://i.imgur.com/soKhOo3.png – Brian Cherdak Jun 29 '13 at 20:40
  • Possible duplicate of [How to fix "Headers already sent" error in PHP](https://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) – axiac Jul 14 '17 at 15:19

1 Answers1

0

Check your config.php file that it does not have blank lines outside (e.g. at the end of the file)

Martin Mandl
  • 721
  • 3
  • 11
  • That seemed to work, but some things didn't, when I downloaded the file, it all is messed up and isn't separated into separate columns and rows. – Brian Cherdak Jun 29 '13 at 20:15
  • Try to open the file using the import function of your spread sheet application. CSV actually stands for Comma Separated Values. You are using semicolons. When importing the file you have to tell which kind of separator (in your case semicolons) you are using ... or you change your code to use commas instead ... – Martin Mandl Jun 29 '13 at 20:47
  • Awesome, that worked perfect! One more thing, how would I rename the row name titles so they look cleaner in the csv output. See: http://i.imgur.com/RacGzog.png Basically the columns, I would like to rename and set in order before downloading: `$result = mysql_query("SHOW COLUMNS FROM " . $table . ""); $i = 0; if (mysql_num_rows($result) > 0) { while ($row = mysql_fetch_assoc($result)) { $csv_output .= $row['Field'] . ","; $i++; } }` – Brian Cherdak Jun 29 '13 at 21:03
  • Instead of writing directly to the csv string, create an array with the results. This array can be rearranged/changed to your liking before creating the csv file. – Martin Mandl Jun 29 '13 at 21:09
  • Thats exactly what I need support with, how does the array need to look like if some help is possible :) – Brian Cherdak Jun 29 '13 at 21:15