Current location: Hot Scripts Forums » Programming Languages » PHP » XML PHP MYSQL- Writing to a xml file


XML PHP MYSQL- Writing to a xml file

Reply
  #1 (permalink)  
Old 03-07-08, 01:25 PM
punky79 punky79 is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
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 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 =  ;  $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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 03-07-08, 01:27 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-07-08, 01:33 PM
punky79 punky79 is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
thanks....I should really have tried this first.
I will give it a go!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 03-07-08, 01:40 PM
punky79 punky79 is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
I have tried this but I am getting an 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 understand in Java I have to have inpout and output streams but not sure how to go about this in PHP.

Can anyone help?

this is my added code:

PHP Code:

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


file_put_contents($filename ,$xml_output); 
just added these 2 lines.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 03-07-08, 01:49 PM
Jay6390's Avatar
Jay6390 Jay6390 is offline
Code Master
 
Join Date: Apr 2007
Location: United Kingdom
Posts: 1,330
Thanks: 0
Thanked 0 Times in 0 Posts
It may just be a file security issue on the machine. check your setting in the properties for the folder / file to make sure you have sufficient priviliges. Also, there is a space in the word Jordan between the J and the o, if that makes any difference.
__________________
Useful Tutorials
[ PHP Video-1-2-3 ] [ MySQL 1-2-3 ]
For any php function reference type

www.php.net/FunctionName
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 03-07-08, 01:51 PM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
You have to escape backslashes. Try:
PHP Code:

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 03-07-08, 01:56 PM
punky79 punky79 is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks guys

I tried the new line Nico but same 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

Could it be my permissions?
How do I check this?
I have a script that uploads images and creates folders to store the images and had no problems with permissions running those...

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 03-07-08, 02:22 PM
punky79 punky79 is offline
Newbie Coder
 
Join Date: Mar 2008
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
I have this working now.
Here is the code I used:

PHP Code:



$filenamepath 
.=   "images.xml";
 
 
$fp fopen($filenamepath,'w');

            
$write fwrite($fp,$xml_output);
 
 echo 
$xml_output
Thanks for your help
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 05-18-09, 05:21 AM
tolga tolga is offline
Newbie Coder
 
Join Date: Apr 2008
Location: /usr/bin/istanbul
Posts: 73
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by punky79 View Post
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 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 =  ;  $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
Hello,

I would like to do exactly the same thing for the same purpose. My question is, how do you get multiple fields from a table and have those written?

Regards,
__________________
Linux user #388977
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Hi & Myphpadmin getting started help php_guru_besar New Members & Introductions 4 03-20-06 12:06 AM
Php Mysql Bug??? tranquilraven PHP 4 03-01-06 04:06 AM
Need help with some php mysql TheTinkeringToad PHP 9 02-01-06 11:56 AM
Complex mysql sorting pb (Get cat_list from cids &pcids with 1 query, willing to pay) aqw PHP 1 06-23-05 08:02 PM
UPDATE: MySQL Auto Backup & Export v1.1 Beyonder General Advertisements 2 03-21-05 03:05 PM


All times are GMT -5. The time now is 07:10 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.