Results 1 to 6 of 6

Thread: php xml problem

  1. #1
    Join Date
    Jan 2007
    Location
    Charlotte, NC
    Posts
    82
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default php xml problem

    So I am using php to create a xml document based on data in a MySql database. But for some reason when I view the xml.php doc on my website the browser doesn't recognize it should be read as an xml doc and I get this error:

    Warning: Cannot modify header information - headers already sent by (output started at blah/xml.php:1) in blah/xml.php on line 3

    I replaced the doc structure of my site with blah.

    Here is the php code:
    PHP Code:
    <?php
     
    header
    ("Content-type: text/xml");
     
    $dbName "dbname";
    $link mysql_connect("mydb""user""pass") or die("Could not connect.");

    $db mysql_select_db($dbName$link);

    $query "select * from item order by id ";

    $result mysql_query($query$link) or die("Could not complete database query");

    $_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
    $_xml .="<portfolio>\r\n";

    for(
    $x=0$x<mysql_num_rows($result); $x++) {
        
    $row mysql_fetch_assoc($result);
        
    $_xml .="\t<item link=\"" $row["link"] . "\">\r\n";
        
    $_xml .="\t<title>" $row["title"] . "</title>\r\n";
        
    $_xml .="\t<descrip>" $row["description"] . "</descrip>\r\n";
        
    $_xml .="\t\t<img>" $row["img"] . "</img>\r\n";
        
    $_xml .="\t</item>\r\n";
    }

    $_xml .="</portfolio>";

    echo 
    $_xml;

    ?>
    It's funny too because when I view the source code of the xml.php file it looks exactly like an xml doc with xml version and everything.

  2. #2
    Join Date
    Jan 2007
    Location
    Charlotte, NC
    Posts
    82
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Ha! **** I fixed it

    I had whitespace before and after the starting/closing php tags <? php and ?>

    Whoduthunkit.

  3. #3
    Join Date
    May 2006
    Location
    Sydney, Australia - Near the coast.
    Posts
    1,995
    Thanks
    0
    Thanked 8 Times in 7 Posts

    Default

    Whoduthunkit.
    ???
    Peter - alotofstuffhere[dot]com - Email Me - Donate via PayPal - Got spare hardware? Donate 'em to me :) Just send me a PM.
    Currently: enjoying the early holidays :)
    Read before posting: FAQ | What you CAN'T do with JavaScript | Form Rules | Thread Title Naming Guide

  4. #4
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    I had whitespace before and after the starting/closing php tags <? php and ?>
    You can use more simple PHP tags
    Code:
    <? 
    
    //Place your PHP code within the start and end tag
    
    ?>

  5. #5
    Join Date
    May 2007
    Location
    Sweden
    Posts
    27
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Post

    Quote Originally Posted by codeexploiter View Post
    You can use more simple PHP tags
    Code:
    <? 
    
    //Place your PHP code within the start and end tag
    
    ?>
    Hi!

    You should never use short php-tag "<?" use instead only "<?php" becuase Parsing short tags makes it impossible to print normal XML documents with inline because PHP would interpret this header as a block and will attempt to execute it!

    Best regards,
    mbrodin

  6. #6
    Join Date
    Jan 2007
    Location
    Charlotte, NC
    Posts
    82
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by tech_support View Post
    ???
    haha

Bookmarks

Posting Permissions

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