Jump to content

XML PHP MYSQL- Writing to a xml file


punky79

Recommended Posts

I have code written to generate xml data in PHP from my MySQL database.  I can display this in my browser using "echo" but wbat I really want is to write this xml data to a seperate xml file so that I can have flash use it.

 

Here is my code:

 

 

<?php require_once('Connections/PhotoABC.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}

$sqluserid = "SELECT `user_id` FROM `user` WHERE `username` = '".$_SESSION['MM_Username']."'";
		$useridqueryresult = mysql_query($sqluserid)
   			or die (mysql_error());
		if (mysql_num_rows($useridqueryresult) > 0) {
    		$row=mysql_fetch_assoc($useridqueryresult);
    		$userid=$row['user_id'];
		}

$sqlimagename = "SELECT `image_name` FROM `gallery` WHERE `user_id` = '$userid'";
		$imagenamequeryresult = mysql_query($sqlimagename)
   			or die (mysql_error());

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

for($x =  0 ;  $x <  mysql_num_rows($imagenamequeryresult) ; $x++){
    $row = mysql_fetch_assoc($imagenamequeryresult);
    $xml_output .= "\t<image>\n";
xml_output .= "\t\t<image>" . $row['image_name'] . "</image>\n";
    $xml_output .= "\t</image>\n";
} 

$xml_output  .=  "</images>"; 

echo $xml_output;

?>

 

I would like to write this xml data to a new xml file called "images" and to save it to this directory

"C:\htdocs\PhotoABC\upload_test\Jordan"

 

Any help would be great :)

Link to comment
https://forums.phpfreaks.com/topic/94931-xml-php-mysql-writing-to-a-xml-file/
Share on other sites

thanks for reply

 

I have been trying to use this function but I keep getting this error:

 

Warning: file_put_contents(C:\htdocs\PhotoABC\upload_test\J ordan) [function.file-put-contents]: failed to open stream: Permission denied in C:\htdocs\PhotoABC\xml.php on line 43

 

I dont know if I need to open inout and output streams or just if my permissions are not set properly?

Do u have any suggestions?

 

$filename= 'C://htdocs//PhotoABC//upload_test//'.$_SESSION['MM_Username'];

file_put_contents($filename ,$xml_output);

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.