Jump to content

problem with php function and xml output


tyrisia

Recommended Posts

Hi all,

 

I'm writing a php script to output xml to a flash movie. The script contains a function siteloklink that outputs an encoded link from the included sitelokpw.php script. The output contains many & characters which i think is stopping my xml from parsing correctly.

 

<? header("Content-Type: text/xml");

require"slpw/sitelokpw.php";

/* include"slpw/sitelokpw.php";
-----
Application: Flash-dB GuestBook Version 2.0
Details:     mySQL and PHP powered GuestBook
Author:      Mohsin Sumar
Website:     http://www.flash-db.com
Support:     http://www.flash-db.com/Board
Notes:       Coments are marked by using comment entries symbols. Eg: // Comment
-----
*/

// Part One - Initiate a mySQL Database Connection
// Database Connectivity Variables and other Variables
   $DBhost = "localhost";   // Database Server
   $DBuser = "";            // Database User
   $DBpass = "";            // Database Pass
   $DBName = "tyrisia";     // Database Name
   $table = "userlink";

   //$user = $slusername;  
   $user = 'admin';           // Database Table

   $i = 0;

   $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error in GuestBook Application: " . mysql_error());

   mysql_select_db($DBName, $DBConn) or die("Error in GuestBook Application: " . mysql_error());

$sql = "SELECT * FROM $table WHERE Username LIKE '%$user%' ORDER BY date";
$alltracks = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
$numalltracks = mysql_num_rows($alltracks);


print('<?xml version="1.0" encoding="UTF-8" ?>' . "\n");
print '<download>';

	 if($numalltracks == 0) {
	    print 'No tracks purchased yet';
	 } else { 
	    for ($i=0; $i<$numalltracks; $i++) {

		$trackname = mysql_result($alltracks, $i, 'title');
		$ahref = mysql_result($alltracks, $i, 'link');
		$date = mysql_result($alltracks, $i, 'date');


	print '<downloadinfo trackname = "' . $trackname . '" link = "' . siteloklink($ahref,1) . '"/>';

	   
	}print '</download>';
?>

 

Can anyone suggest a way round the problem?

 

xml error is "A semi colon character was expected"

 

thanks in advance:)

Link to comment
https://forums.phpfreaks.com/topic/99397-problem-with-php-function-and-xml-output/
Share on other sites

you should redo your xml so it looks something like this instead of using attributes. you can parse anything by putting it in CDATA. Otherwise you will need to strip and remove all the illegal characters in php before it hits the parser.

 

<?PHP
$query = "SELECT * FROM $table WHERE Username LIKE '%$user%' ORDER BY date"; 

$xmlresult = mysql_query($query, $DBConn) or die("Data not found.");

$xml_output .= "<download>"

for($x = 0 ; $x < mysql_num_rows($xmlresult) ; $x++){

    $items = mysql_fetch_assoc($xmlresult);


    $xml_output .=  "<item>"
          $xml_output .=   "<title><![CDATA[" .$title."]]></title>"
          $xml_output .=    "<content><![CDATA[" .$content."]]></content>"


    $xml_output .= " </item>"

}

$xml_output .= "</download>"

echo $xml_output;

?>

 

EDIT yeah what rhodesa posted.

 

 

 

   

yeah it will work for php4 you will need to change the way you parse it in flash though.

 

example xml parser for flash

myXML = new XML()
        myXML.ignoreWhite = true
///change to your php xml file
        myXML.load("yourxml.php") 

myXML.onLoad = function(success){
        if(success){


            var root = this.firstChild
            nodes = root.childNodes

		  // output each item
            for(var i=0; i<nodes.length; i++) {        
                

                                subnodes = nodes[i].childNodes
			var trackname = subnodes[0].firstChild.toString()
			var ahref  = subnodes[1].firstChild.toString()
			var date = subnodes[2].firstChild.toString()

		 ///you can put it into a array or dynamically attach a movie clip here 




            }

		//end loop
//you can assign your array to a dataprovider here or whatexver

        } else trace("Error loading XML document")

    } 

 

 

 

 

 

Try this...i updated the print line and also found you were missing a brace:

 

<?php
header("Content-Type: text/xml");

require"slpw/sitelokpw.php";

/* include"slpw/sitelokpw.php";
-----
Application: Flash-dB GuestBook Version 2.0
Details:     mySQL and PHP powered GuestBook
Author:      Mohsin Sumar
Website:     http://www.flash-db.com
Support:     http://www.flash-db.com/Board
Notes:       Coments are marked by using comment entries symbols. Eg: // Comment
-----
*/

// Part One - Initiate a mySQL Database Connection
// Database Connectivity Variables and other Variables
  $DBhost = "localhost";   // Database Server
  $DBuser = "";            // Database User
  $DBpass = "";            // Database Pass
  $DBName = "tyrisia";     // Database Name
  $table = "userlink";

  //$user = $slusername;  
  $user = 'admin';           // Database Table

  $i = 0;

  $DBConn = mysql_connect($DBhost,$DBuser,$DBpass) or die("Error in GuestBook Application: " . mysql_error());

  mysql_select_db($DBName, $DBConn) or die("Error in GuestBook Application: " . mysql_error());

  $sql = "SELECT * FROM $table WHERE Username LIKE '%$user%' ORDER BY date";
  $alltracks = mysql_query($sql, $DBConn) or die("Error in GuestBook Application: " . mysql_error());
  $numalltracks = mysql_num_rows($alltracks);

  print('<?xml version="1.0" encoding="UTF-8" ?>' . "\n");
  print '<download>';

  if($numalltracks == 0) {
    print 'No tracks purchased yet';
  } else { 
    for ($i=0; $i<$numalltracks; $i++) {
      $trackname = mysql_result($alltracks, $i, 'title');
      $ahref = mysql_result($alltracks, $i, 'link');
      $date = mysql_result($alltracks, $i, 'date');
      print '<downloadinfo trackname = "' . htmlspecialchars($trackname) . '" link = "' . htmlspecialchars(siteloklink($ahref,1)) . '"/>';
    }
  }
  print '</download>';
?>

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.