Jump to content

Recommended Posts

hi,

 

i run the below code i got the following error and also display output normal way instead of xml entries.plz help that what's the mistake in my code

 

 


<?
header("Content-type: text/xml");
$host = "localhost";
$user = "root";
$pass = "root";
$database = "DataMiningdb";

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");

$query = "SELECT * FROM vehicles ORDER BY vehicle_id DESC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");

$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<entries>\n";

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
    $row = mysql_fetch_assoc($resultID);
    $xml_output .= "\t<entry>\n";
    $xml_output .= "\t\t<vehicle_id>" . $row['vehicle_id'] . "</vehicle_id>\n";
        // Escaping illegal characters
        $row['vehicle_make'] = str_replace("&", "&", $row['vehicle_make']);
        $row['vehicle_make'] = str_replace("<", "<", $row['vehicle_make']);
        $row['vehicle_make'] = str_replace(">", ">", $row['vehicle_make']);
        $row['vehicle_make'] = str_replace("\"", """, $row['vehicle_make']);
    $xml_output .= "\t\t<vehicle_make>" . $row['vehicle_make'] . "</vehicle_make>\n";
    $xml_output .= "\t</entry>\n";
}

$xml_output .= "</entries>";
echo $xml_output;

?> 

 

output:

 

 

Warning: Cannot modify header information - headers already sent by (output started at F:\Facebook\furniture11\Data Mining1\public_html\xmlparsing.php:1) in F:\Facebook\furniture11\Data Mining1\public_html\xmlparsing.php on line 2

5 Bayliner 5 Bayliner 5 Bayliner 4 Bayliner 4 Bayliner 4 Bayliner 3 Baja Marine 3 Baja Marine 3 Baja Marine 2 Miscellaneous 2 Miscellaneous 2 Miscellaneous 1 Miscellaneous 1 Miscellaneous 1 Miscellaneous

Link to comment
https://forums.phpfreaks.com/topic/114381-problem-in-conversion-of-xml/
Share on other sites

Remove all space before sending any header. in your code their is a space before opening php tag....

refer to code below...

 

<?php
header("Content-type: text/xml");
$host = "localhost";
$user = "root";
$pass = "root";
$database = "DataMiningdb";

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");

$query = "SELECT * FROM vehicles ORDER BY vehicle_id DESC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");

$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<entries>\n";

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
    $row = mysql_fetch_assoc($resultID);
    $xml_output .= "\t<entry>\n";
    $xml_output .= "\t\t<vehicle_id>" . $row['vehicle_id'] . "</vehicle_id>\n";
        // Escaping illegal characters
        $row['vehicle_make'] = str_replace("&", "&", $row['vehicle_make']);
        $row['vehicle_make'] = str_replace("<", "<", $row['vehicle_make']);
        $row['vehicle_make'] = str_replace(">", ">", $row['vehicle_make']);
        $row['vehicle_make'] = str_replace("\"", """, $row['vehicle_make']);
    $xml_output .= "\t\t<vehicle_make>" . $row['vehicle_make'] . "</vehicle_make>\n";
    $xml_output .= "\t</entry>\n";
}

$xml_output .= "</entries>";
echo $xml_output;

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.