Jump to content

woodsonoversoul

Members
  • Posts

    142
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

woodsonoversoul's Achievements

Member

Member (2/5)

0

Reputation

  1. Thanks so much, that's exactly what I'll do. That's one of the best forum responses I've ever gotten. Thanks again!
  2. I thought the beauty of XML was that it was plain text. I'm not really familiar with "multidimensional" (or database within a database) databases, and, to me, they sound like almost they same amount of work to traverse/work though as XML. If I'm going about this totally the wrong way I can change it, I'm really just looking for some guidance...
  3. changed what's the text stored in the DB to: <?xml version="1.0"?><userFavSongs></userFavSongs> still no luck...
  4. Here's the code I'm using: if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_array($result)){ //check if the current songs artist is in the artist array $userFavSongs = $row['favorite_songs']; echo $userFavSongs; }//end while //I need to define this as <xml> //and probably put everything in containing tags $userFavSongsXml = simplexml_load_string($userFavSongs) or die ("Unable to load XML!"); ; $userFavSongsXmlRoot = $userFavSongsXml->userFavSongs[0]; $userFavSongsArray = array(); //assign songs to array foreach ($userFavSongsXml->song as $song) { $userFavSongsArray = $song; } //$userFavSongsArray = $userFavSongsXmlRoot->getElementsByTagName('song'); if($incORdec == 'inc'){ $userFavSongsXml->addChild('song', $songId); $userFavSongs = (string)$userFavSongsRoot; } And I'm getting an, "Unable to load XML" error. Is my xml not formatted correctly? Is one empty element illegal?
  5. Thanks rhodesa, still not really seeing how to create and add nodes, or convert from text to xml...
  6. What I'm trying to do is: 1) Retrieve text (formatted as xml) from the database 2)Convert the text to xml 3)Add a single element to the root of the xml 4)Turn the xml back into text 5)Update the database with the new text (xml) The xml/text I have stored in the database looks like: <userFavSongs id="root"></userFavSongs> simpleXML looks like it will work, but I'm open to any methods available. I'm trying to add in a node that looks like <song>some song id</song> If any of this looks incorrect or like I'm doing unnecessary steps, let me know, this is my first time working with strings converted to xml. So all help is appreciated. Anyone have any tutorials/examples? Thanks
  7. commenting out those two lines still leaves errors. Does my header look right? New error from commenting out error producing lines: 1Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '1' at line 1
  8. moving the header function didn't remove the warning, just put it at a different line number. What I'm trying to do is pull the xml stored in the table 'users' and the field 'favorite_songs'. Then either add a song to that xml or take one away. Could I put the queries in different functions in the script, would that help? Do I really need to write a whole different script to handle a single query and a few lines of code? Surely there are times when developers need to do multiple queries in a single function...
  9. I get the following errors when accessing the page directly (location + setUserFavSongs.php?username=danwoods&songId=tdb2009-01-29s2s02&incORdec=inc as the address) Warning: Cannot modify header information - headers already sent by (output started at /opt/lampp/htdocs/musicneverstopped/php/setUserFavSongs.php:2) in /opt/lampp/htdocs/musicneverstopped/php/setUserFavSongs.php on line 7 Fatal error: Call to a member function getElementsByTagName() on a non-object in /opt/lampp/htdocs/musicneverstopped/php/setUserFavSongs.php on line 45 How would I clear the value of mysql_query()?
  10. This is a script called from javascript, ie: xmlHttp.open("GET", "php/setUserFavSongs.php?" + params, true); Where would I expect to see the echo? I don't see it on the main page...
  11. Hello all. I'm tryign to update some records (for the first time) with; //update DB $sql = mysql_query("UPDATE users SET favorite_songs = '$userFavSongs' WHERE username = '$username'"); //check to see if the query went through if (!mysql_query($sql, $con)){ die('Error: ' . mysql_error()); } But the DB never updates. Anyone see any problems with the syntax? Whole script is: <?php //turn on error reporting ini_set('display_errors', 'On'); error_reporting(E_ALL | E_STRICT); header('Content-Type: text/xml'); //pull variables //need to do some error checking here $username = ($_GET['username']); $songId = ($_GET['songId']); $incORdec = ($_GET['incORdec']); //connect with database $con = mysql_connect("localhost","root",""); if(!$con){ die('Could not connect: ' . mysql_error()); } mysql_select_db("musicneverstopped", $con); //end connecting to database //declare placeholders $result = mysql_query("SELECT favorite_songs FROM users WHERE username = '$username'"); //error check - see if this is safe to remove later if(!$result){ die(mysql_error()); } //check if any results were returned if(mysql_num_rows($result) > 0){ while($row = mysql_fetch_array($result)){ //check if the current songs artist is in the artist array $userFavSongs = $row['favorite_songs']; }//end while $userFavSongsArray = $userFavSongs->getElementsByTagName('song'); if($incORdec == 'inc'){ $userFavSongs = $userFavSongs . "<song>". $songId . "</song>"; } else{ foreach($userFavSongsArray as $a){ if($a == $songId){ $userFavSongsArray =- $a; }//end if }//end foreach foreach($userFavSongsArray as $b){ $userFavSongs =+ "<song>" . $b . "</song>"; }//end foreach }//end else //update DB $sql = mysql_query("UPDATE users SET favorite_songs = '$userFavSongs' WHERE username = '$username'"); //check to see if the query went through if (!mysql_query($sql, $con)){ die('Error: ' . mysql_error()); } }//end if ////////////////////////////////////////// //close database connection mysql_close($con);//close mysql connection ?>
×
×
  • 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.