473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

XML PHP MYSQL- Writing to a xml file

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]<?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;

?>[/PHP]

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 :)
Mar 7 '08 #1
4 2300
Markus
6,050 Expert 4TB
Have a look at this tutorial on creating files: http://w3schools.com/php/php_file.asp

You could just create a file, then fwrite() the xml to it and save it as an xml file.
:)
Mar 7 '08 #2
Thanks
I will have a look at doing it that way...

I have tried it using "file_put_contents"
But get this error:

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

Could this have to do with permissions?
I have uploaded images and created folders with no problem?

Thanks for any help :)

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

file_put_contents($filename ,$xml_output);[/PHP]
Mar 7 '08 #3
I have this working now.
Here is the code I used:
[PHP]
$filenamepath .= "images.xml";

$fp = fopen($filenamepath,'w');

$write = fwrite($fp,$xml_output);

echo $xml_output; [/PHP]
Thanks for your help
Mar 7 '08 #4
Markus
6,050 Expert 4TB
I have this working now.
Here is the code I used:
[PHP]
$filenamepath .= "images.xml";

$fp = fopen($filenamepath,'w');

$write = fwrite($fp,$xml_output);

echo $xml_output; [/PHP]
Thanks for your help
Welcome mate :)
see you around
Mar 7 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: William Drew | last post by:
REQUEST FOR DISCUSSION (RFD) unmoderated group comp.databases.mysql This is an invitation to discuss the following proposal to create newsgroup comp.databases.mysql. Please note that YOU...
2
by: Cathy Hui | last post by:
Do u know why do i get the following message when trying to build the MySql-Python (1.2.0) on my Solaris 8 system? (with mysql 4.0.21 and python 2.4). thanks! error mesg: ld: fatal:...
0
by: Girish Agarwal | last post by:
--0-474210375-1058976151=:31789 Content-Type: text/plain; charset=us-ascii Content-Id: Content-Disposition: inline Note: forwarded message attached. __________________________________
0
by: Miguel Perez | last post by:
Hi Guys: Does anyone know how come I'm getting a lot of mysql processes when I start mysql server for the first time. When I type top it showed the following: 5:33pm up 15 min, 4 users, ...
0
by: Chris Moy | last post by:
SEND-PR: -*- send-pr -*- SEND-PR: Lines starting with `SEND-PR' will be removed automatically, as SEND-PR: will all comments (text enclosed in `<' and `>'). SEND-PR: From: moyc To:...
2
by: Saqib Ali | last post by:
I installed mySQL and have it running.... but I think I made a mistake somewhere along the line...... I believe I did follow the instructions that were provided with the distribution at:...
14
by: mistral | last post by:
Need php script to create mySQL database programmatically; since hosting configuration may not allow create database from script, script also need eliminate/rewrite all restrictions in appropriate...
3
by: menzies | last post by:
Hi, I"m new to this forum, but I have been trying all day to install DBD::mysql onto my Intel MacBook. I've read lots of forums pages and none have gotten me to a successful 'make test' or a...
6
Atli
by: Atli | last post by:
This is an easy to digest 12 step guide on basics of using MySQL. It's a great refresher for those who need it and it work's great for first time MySQL users. Anyone should be able to get...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.