Jump to content

Recommended Posts

Hello freaks

 

 

Cannot Write XML File using PHP/MySQL. I got some error

 

Warning: domnode::append_child() expects parameter 1 to be object, null given in C:\wamp\www\xml\sitemap3.php on line 9

Warning: Cannot modify header information - headers already sent by (output started at C:\wamp\www\xml\sitemap3.php:9) in C:\wamp\www\xml\sitemap3.php on line 30

Fatal error: Call to a member function append_child() on a non-object in C:\wamp\www\xml\sitemap3.php on line 36

 

my code is

 

<?php
$username="root";
$password="";
$database="linksubmission";

// Start XML file, create parent node
$doc = domxml_new_doc("1.0");
$node = $doc->create_element("Category");
$parnode = $doc->append_child($node);

// Opens a connection to a MySQL server
$connection=mysql_connect (localhost, $username, $password);
if (!$connection) {
  die('Not connected : ' . mysql_error());
}

// Set the active MySQL database
$db_selected = mysql_select_db($database, $connection);
if (!$db_selected) {
  die ('Can\'t use db : ' . mysql_error());
}

// Select all the rows in the markers table
$query = "SELECT * FROM tbl_cat ";
$result = mysql_query($query);
if (!$result) {
  die('Invalid query: ' . mysql_error());
}

header("Content-type: text/xml");

// Iterate through the rows, adding XML nodes for each
while ($row = @mysql_fetch_assoc($result)){
  // ADD TO XML DOCUMENT NODE
  $node = $doc->create_element("Category");
  $newnode = $parnode->append_child($node);

  $newnode->set_attribute("Sub Cat Id", $row['sub_cat_id']);
  $newnode->set_attribute("Cat Name", $row['cat_name']);

}

$xmlfile = $doc->dump_mem(jgj);
echo $xmlfile;

?>

I am not understanding how can i remove this error

currently i am using php5.2.3

 

Thanks

Beboo

Link to comment
https://forums.phpfreaks.com/topic/109388-mysql-and-xml-problem/
Share on other sites

as far as line 9 and 36 error:

i'd echo out and find what the value is before passing it

 

Warning: Cannot modify header information 

Clear any whitespace in your closing ?> tag

currently its like this:

 

$xmlfile = $doc->dump_mem(jgj);

echo $xmlfile;

 

?>

 

needs to be:

 

$xmlfile = $doc->dump_mem(jgj);

echo $xmlfile;

?>

 

 

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.