0

Hey all. I'm trying to save A XML file using php. here is my code, the connection to the DB is okay and all, i can use $dom->saveXML() but the save function isn't saving nothing. please help.

<?
$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 Listing_Arnona WHERE 1";
$result = mysql_query($query);
if (!$result) {  
  die('Invalid query: ' . mysql_error());
} 



// Iterate through the rows, adding XML nodes for each

while ($row = @mysql_fetch_assoc($result)){  
  // ADD TO XML DOCUMENT NODE  
  $node = $dom->createElement("marker");  
  $newnode = $parnode->appendChild($node);   
  $newnode->setAttribute("Price",$row['Price']);
  $newnode->setAttribute("PriceS", $row['Price']);  
  $newnode->setAttribute("address", $row['street_name']);  
  $newnode->setAttribute("NumRooms", $row['Room_Num']);  
  $newnode->setAttribute("PROMO", $row['PROMO']);
} 

$dom->formatOutput = true; 
$test1 = $dom->saveXML(); // put string in test1
$dom->save('test1.xml'); // save as file

?>
5
  • Do you have write permissions to test1.xml? Are you able to successfully output $test1 to the browser? Commented Mar 18, 2011 at 2:04
  • What does $dom->save('test1.xml') return? If it returns false, it can't write the file (and most probably that is a permissions issue). Commented Mar 18, 2011 at 2:04
  • isn't saving nothing? Ah, gotta love them double negatives. What is it saving? Commented Mar 18, 2011 at 2:05
  • @Tim $test1 in browser is alright, i didn't check what it returns, i have full root access Commented Mar 18, 2011 at 2:06
  • having full root access doesn't mean that script can write to that particular directory. Can you check if it's indeed able to write to that directory? Commented Mar 18, 2011 at 2:09

1 Answer 1

1

The problem as everyone pointed out was the writing permissions. i opend a new folder name 'xml' with chmod 777 and changed the code to:

$dom->save('xml/test1.xml');

Thank you all.

Sign up to request clarification or add additional context in comments.

1 Comment

Excuse me for being blunt, but you didn't check the return value of the function before posting? Priceless... php.net/manual/en/domdocument.save.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.