dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: php to xml error in admin panel

Threaded View

  1. #1
    Senior Member
    Join Date
    Aug 2006
    Posts
    293

    php to xml error in admin panel

    hi all,

    hope that someone might be able to answer this question for me.

    i have an flash based mp3 player that reads an xml playlist (this works fine)
    i need to create a very simplistic cms for the playlist to be updated. this is where my troubles start.

    i have a couple of php docs that in one you can enter the name/artist/path to mp3 - when the user clicks add - it passes the data onto another php doc, this creates the xml playlist.

    i needed to include a CDATA option and from here on in it doesn't play ball.

    what happens now is that the first can be inserted into the xml (i have checked and it does appear in the xml doc) but on return to the index.php doc it tells me there is an error in parsing the xml and i can not add any further tracks.

    without the cdata in the xml doc it does work okay - but i need the cdata included.

    does anyone know what i am doing wrong? this is the index.php code (this is where you enter data and the user returns to once added)
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd" >
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head><title>Add Songs</title></head>
    <style type="text/css">
    table {
        border:1px dotted #ccc;
        width:100%;
    }
    td {
         background-color:#aaa;
        color:#fff;
    }
    fieldset { border:0; }
    label { margin-right:5px; }

    </style>
    <body>
    <form action="processForm.php" method="post">
    <fieldset>
    <label for="name">Name:</label> <input type="text" id="name" name="name"/><br />
    <label for="artist">Artist:</label><input type="text" id="artist" name="artist" /><br />
    <label for="path">Path:</label> <input type="text" id="path" name="path" /> <br />
    <select name="action">
    <option value="ins">Insert</option>
    <option value="del">Delete</option>
    </select>
    <input type="submit" />
    </fieldset>
    </form>
    Current entries:
    <?php
    function start_tag($parser$name$attrs){
        global 
    $table_string;
        
    $table_string .= "<tr><td>$attrs[title]</td><td>$attrs[artist]</td><td>$attrs[path]</td></tr>";
    }
    function 
    end_tag($parser$name){}
    $parser xml_parser_create();
    xml_parser_set_option($parserXML_OPTION_CASE_FOLDING0);
    xml_set_element_handler($parser"start_tag""end_tag");
    $table_string "<table>
            <tr><th>Title</th><th>Artist</th><th>Path</th></tr>"
    ;
    xml_parse($parserfile_get_contents("playlist.xml")) or die("Error parsing XML file");
    $table_string .= "</table>";
    echo 
    $table_string;

    ?>
    </body>
    </html>
    and this is the processform.php code - this is where the xml document is generated...

    PHP Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Adding Songs...</title>
    <style type="text/css">
    em {
        text-align:center;
    }
    </style>
    </head>
    <body>
    <?
    $songs 
    = Array();
    function 
    start_element($parser$name$attrs){
        global 
    $songs;
        if(
    $name == "song"){
            
    array_push($songs$attrs);
        }
    }
    function 
    end_element ($parser$name){}
    $playlist_string file_get_contents("playlist.xml");
    $parser xml_parser_create();
    xml_set_element_handler($parser"start_element""end_element");
    xml_parser_set_option($parserXML_OPTION_CASE_FOLDING0);
    xml_parse($parser$playlist_string) or die("Error parsing XML document.");
    print 
    "<br />";
    if(
    $_POST['action'] == "ins"){
        
    array_push($songs, Array(
                    
    "title" => $_POST['name'],
                    
    "artist" => $_POST['artist'],
                    
    "path" => $_POST['path']));
        
    $songs_final $songs;
    }else if(
    $_POST['action'] == "del"){
        
    $songs_final = Array();
        foreach(
    $songs as $song){
            if(
    $song['title'] != $_POST['name']){
                
    array_push($songs_final$song);
            }
        }
    }
    $write_string "<content><songs>";
    foreach(
    $songs_final as $song){
        
    $write_string .= "<song title=\"$song[title]\" artist=\"$song[artist]\" path=\"$song[path]\"><![CDATA[$song[artist]]]>";
    }
    $write_string .= "</songs></content>";
    $fp fopen("playlist.xml""w+");
    fwrite($fp$write_string) or die("Error writing to file");
    fclose($fp);
    print 
    "<em>Song inserted or deleted successfully :)<em><br />";
    print 
    "<a href=\"index.php\" title=\"return\">Return</a>";
    ?>
    </body>
    </html>
    i have also attached the actual docs if anyone would like to test...
    really hope someone can sort the errors out for me - been at it for a few days now!
    Attached Files Attached Files

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center