tags:

views:

465

answers:

4

I have generated a XML file automatically from the below code.

if (isset($_POST["song"])&& $_POST['song'] != "") {
    $song = $_POST["song"];
} else {
    $song = array();
}
$dom = new DOMDocument("1.0");
// display document in browser as plain text 
// for readability purposes

// create root element
$root = $dom->createElement("playlist");
$dom->appendChild($root);
$root->setAttribute('version', "1");
$root->setAttribute('xmlns', "http://xspf.org/ns/0/");
$rootnext = $dom->createElement("trackList");
$root->appendChild($rootnext);
foreach ($song as $counter) {
    $tokens = ",";
    $tokenized = strtok($counter, $tokens);
    // create child element
    $song = $dom->createElement("track");
    $rootnext->appendChild($song);
    $song1 = $dom->createElement("creator");
    $song->appendChild($song1);
    $text = $dom->createTextNode("www.musicking.in");
    $song1->appendChild($text); 
    $song1 = $dom->createElement("title");
    $song->appendChild($song1);
    // create text node
    $text = $dom->createTextNode($tokenized);
    $song1->appendChild($text); 
    $tokenized = strtok($tokens);
    $song1 = $dom->createElement("location");
    $song->appendChild($song1);
    $text = $dom->createTextNode($tokenized);
    $song1->appendChild($text); 
}
$dom->save("playlist.xml");

Actually after generating XML file it’s storing in the root directory.

Can you please tell me how to store the generated XML file into MySQL database?

After generating XML file I have to call that file. I am using below code to call:

<object data="musicplayer.swf?autostart=true&playlist=playlist.xml" type="application/x-shockwave-flash" width="400" height="300">
    <param name="movie" value="musicplayer.swf?autostart=true&playlist=playlist.xml"/>
</object>

Please tell me how to store and retrieve this playlist.xml file from mysql database?

A: 

i think it makes no sense for you to store it in the database, if you use the solution from the other question that singlefile problem IS SOLVED (AGAIN!!), if you store it in the database and get it from there or whatever this might also work and maybe even the better solution, but this will not fix your problem with the wrong values as this php script will get EXACTLY the same values as the other one, it will result in EXACTLY the same thing.

Again:

CHECK THE CODE WHERE YOU POST THE DATA TO THE PHP SCRIPT!

Flo
-1 what's with all the yelling?
Jonathan Fingland
am sorry if i ask so many timesbut am trying here... befor u gave solution using microtime() function .....actually thats superbbut i dont know why, its creating xml file each time but its not accessing that file. its showing only the playlist which we will select first.
musicking123
Look at his other questions.There are multiple things that could go wrong:The post script sends the same data again -> u get the same stuffThe Flash does not load the right xml -> u get the same stuffcaching issues.Maybe other things but none of them has to to anything with this. If the other script does the wrong thing, passing the same data to the flash in another way wont make it any better. Do debugging, or show other files here, with this noone will be able to help you.
Flo
other files means?
musicking123
as people keep downvoting this answer i think they have to know better then i do .. ask them
Flo
flo am i distrubing u?
musicking123
actually am in learning stage thats why am asking this many times
musicking123
its ok but if you ignore what i already said in other posts, and i get downvoted for pointing out the important stuff, i dont really feel like keep going
Flo
A: 

Use the DOMDocument->saveXML method instead to get the XML document as a string.

Gumbo
+1  A: 

Use DOMDocument::saveXML() to get a string representation of your xml file and insert this string into an approrpiate column in your database. Depending on the size fo your data use a column of type TINYBLOB (2^8 bytes), BLOB (2^16 bytes), MEDIUMBLOB (2^24 bytes) or LONGBLOB (2^32 bytes) (if using MySQL or an appropriate data type in the RDBMS of your choice).

Stefan Gehrig
am trying to do this.<?php$con = mysql_connect("localhost","music123","password");if (!$con) { die('Could not connect: ' . mysql_error()); }mysql_select_db("my_db", $con);$sql="INSERT INTO xml (File)VALUES('**********')";mysql_close($con)?> what i have to give ****** for this?
musicking123
******* should be " . mysql_escape_string($xmlString) . "
Stefan Gehrig
can u please check the above answer code , its not working
musicking123
$xmlString = $dom->saveXML(); instead of DOMDocument::saveXML();You must assign the output of the saveXML() method to some variable. And you also have to call the method on the $dom object.
Stefan Gehrig
And please make yourself familiar with the core concepts of PHP... That'll make understanding the answers on SO a lot more easier.
Stefan Gehrig
thank u........sure am learning php
musicking123
ya i changed .....but its not connecting to databaseanything wrong in connecting to database code
musicking123
Please have a look at some PHP/MySQL tutorials or post a seond question as this cleary gets out of scope of this question. Some hint: you generated an SQL-query in your $sql variable but you never send the query to the server.
Stefan Gehrig
ok sure........................................
musicking123
A: 
<?php 
if(isset($_POST["song"])&& $_POST['song'] != "") 
    {
        $song = $_POST["song"];
    }
    else {$song=array();} 
$dom = new DOMDocument("1.0");
// display document in browser as plain text 
// for readability purposes

// create root element
$root = $dom->createElement("playlist");
$dom->appendChild($root);
$root->setAttribute('version', "1");
$root->setAttribute('xmlns', "http://xspf.org/ns/0/");
$rootnext = $dom->createElement("trackList");
$root->appendChild($rootnext);
foreach ($song as $counter) {
    $tokens = ",";
    $tokenized = strtok($counter, $tokens);
// create child element

$song = $dom->createElement("track");
$rootnext->appendChild($song);
$song1 = $dom->createElement("creator");
$song->appendChild($song1);
$text = $dom->createTextNode("www.musicking.in");
$song1->appendChild($text); 
$song1 = $dom->createElement("title");
$song->appendChild($song1);
// create text node
$text = $dom->createTextNode($tokenized);
$song1->appendChild($text); 
$tokenized = strtok($tokens);
$song1 = $dom->createElement("location");
$song->appendChild($song1);
$text = $dom->createTextNode($tokenized);
$song1->appendChild($text); 

}
DOMDocument::saveXML();

$con = mysql_connect("localhost","music123_sri","password");
 if (!$con) 
  { die('Could not connect: ' . mysql_error()); } 
mysql_select_db("music123_telugu", $con);
 $sql="INSERT INTO xml (File) VALUES (" . mysql_escape_string($xmlString) . ")"; 
 $data = mysql_query("SELECT File FROM xml")

 $info = mysql_fetch_array( $data );
?>
<object data="musicplayer.swf?autostart=true&playlist=<?php $info ?>"      type="application/x-shockwave-flash" width="400" height="300"><param name="movie"   value="musicplayer.swf?autostart=true&playlist=<?php $info ?>"/></object>



can u check the above code its not working.
musicking123
INSERT INTO xml (File) VALUES <- (why (File)?? the name of the table has to be heredid you create a database table at all? which fields are in there?<?php $info ?> will not work, it will be replaced with you whole xml as a string, you will have to use a id or something like that here which is kind of worthless if you cant access database with flash (I guess you dont want to change your flash plugin).But as said before, even if you get this working, it will just do the same as the xml thing before (same error) but you have to do a lot of stuff to get there.
Flo
ya xactly what u said is rite.am not understanding which one is perfect to try?Flo can u help me please..if am bugging just leave it
musicking123
stick with the xml solution, forget about the sql stuff, that would be tons of work and make no difference at all.add:var_dump($_POST["song"]); somewhere so you can see what is posted to the php file. Then try a little around and compare the output with what is playing in the flashplayer
Flo
am trying it now............................
musicking123
if i place var_dump ,when i open player.php its showing selected songs as text on the screen
musicking123
thats what it should do,and are the same songs in the flashplayer? is everything working? what is the text showing when the flashplayer has the wrong songs?
Flo
ya same songs. its working but showing previous songs only.the text showing the presently selected songs
musicking123
wow the text is ok but the player is wrong? that is weird.Ok put a var_dump($string); somewhere after $string is set, and then open the source code in browser and look if the <object data="... matches with the text outout of string (check if the right xml filename is passed to the flashplayer)
Flo
musicking123
hmm ok so the string is not passed to the player that is very strange.Try putting the output with echo, but this seems strange:replace ?><object.... with:echo '<object data="musicplayer.swf?autostart=true?>
Flo
musicking123
then replace the $string= line with:$string = $string[1] ."-". $string[0]. ".xml";then is the filename a xml
Flo
musicking123
then take a look in those xml files if they are ok
Flo
ya............hey its workingthank u very muchbut deleting generated xml files?we can run cron jobs rite?
musicking123
trying to write cron.php
musicking123
ya i wrote cron job and its working perfectly.thank u Flo for ur help
musicking123
nice :)accept answer and vote up would be nice :)
Flo
for the previous question i accepted ur answer and voted up
musicking123