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.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post

    Trying to output a comma delimited file (csv)

    Hello, I am trying to create a script that output a csv file from data I am querying from a mySQL table. Keep getting this error:

    Fatal error: Call to undefined function phpheader() in /home/foo/bar/exportmycsv.php on line 1

    Code:
    <?php
    header('Content-type: application/x-msdownload');
    header('Content-Disposition: attachment; filename=exportcsv.csv');
    header('Pragma: no-cache');
    header('Expires: 0');
    include("myconnect.php");
    $sql = "SELECT theDate,theTitle,theContent FROM mycal ORDER BY theDate ASC";
    $result = mysql_query($sql);
    if($result){
    echo "Subject,Start Date,Start Time,End Date,End Time,All Day Event,Description,Location,Private\r\n"; //header
    while($row = mysql_fetch_array($result)){
    echo "\"$row[theTitle]\",\"$row[theDate]\",\"false\",\"$row[theDate]\",\"false\",\"false\",\"$row[theContent]\",\",\"false\"\r\n"; //data
    } 
    }
    ?>

    can someone tell me what I am doing incorrect? it all appears satisfactory to my eyes

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    I don't see any call to phpheader()... is that script called exportmycsv.php? Are you looking at the right folder?

  • Users who have thanked Fumigator for this post:

    Bobafart (09-19-2009)

  • #3
    Senior Coder
    Join Date
    Jul 2009
    Location
    South Yorkshire, England
    Posts
    2,318
    Thanks
    6
    Thanked 304 Times in 303 Posts
    Add a blank line after the opening <?php tag and see if that makes any difference. What format are you saving the file in? Rich text, by any chance?

  • Users who have thanked MattF for this post:

    Bobafart (09-19-2009)

  • #4
    New Coder
    Join Date
    Sep 2009
    Location
    Bangalore , India
    Posts
    10
    Thanks
    0
    Thanked 2 Times in 2 Posts
    check this line
    ---------------

    echo "\"$row[theTitle]\",\"$row[theDate]\",\"false\",\"$row[theDate]\",\"false\",\"false\",\"$row[theContent]\",\",\"false\"\r\n"; //data

    replace this line with the following line and try

    echo "\"" . $row[theTitle] . "\",\"" . $row[theDate] . "\",\"false\",\"" . $row[theDate] . "\",\"false\",\"false\",\"" . $row[theContent] . "\",\",\"false\"\r\n"; //data

  • Users who have thanked karthikm19 for this post:

    Bobafart (09-19-2009)

  • #5
    New Coder
    Join Date
    Aug 2009
    Posts
    84
    Thanks
    1
    Thanked 7 Times in 7 Posts
    It'd be much better to do:
    Code:
    echo '"'. $row['theTitle'] .'","'. $row['theDate'] .'","false","'. $row['theDate'] .'","false","false","'. $row['theContent'] .'",","false"'. "\r\n"; //data

  • Users who have thanked orca8767 for this post:

    Bobafart (09-19-2009)

  • #6
    Regular Coder
    Join Date
    Dec 2006
    Posts
    417
    Thanks
    168
    Thanked 1 Time in 1 Post
    Quote Originally Posted by orca8767 View Post
    It'd be much better to do:
    Code:
    echo '"'. $row['theTitle'] .'","'. $row['theDate'] .'","false","'. $row['theDate'] .'","false","false","'. $row['theContent'] .'",","false"'. "\r\n"; //data
    Thanks for all of your help gents

    Orca, you rock. The problem was solved with your fabulous post.

    Thanks again all


  •  

    Posting Permissions

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