jimmyoneshot Posted April 27, 2010 Share Posted April 27, 2010 I'm passing a variable 'userid' to my php file and trying to select all of the records from my table 'userlinks' which match that variable and setting this as $userlinks. Then I'm trying to select all the records from my 'links' table based on this and output them as xml but when I run the file I'm getting the error "The XML page cannot be displayed " "Invalid at the top level of the document. Error processing resource " "Line..." Here's my php code but it looks fine to me:- <?php header("Content-type: text/xml"); $host = ""; $user = ""; $pass = ""; $database = ""; $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); mysql_select_db($database, $linkID) or die("Could not find database."); $param_userid = $_POST["userid"]; $text = $param_userid; $userlinks = "SELECT linkid FROM userlinks WHERE userid = '$param_userid' AND favourited = 'N'"; $query = "SELECT * FROM links WHERE linkid = '$userlinks' ORDER BY label ASC"; $resultID = mysql_query($query, $linkID) or die("Data not found."); $xml_output = "<?xml version=\"1.0\"?>\n"; $xml_output .= "<links>\n"; for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ $row = mysql_fetch_assoc($resultID); $xml_output .= "\t<link>\n"; $xml_output .= "\t\t<linkid>" . $row['linkid'] . "</linkid>\n"; $xml_output .= "\t\t<categoryid>" . $row['categoryid'] . "</categoryid>\n"; $xml_output .= "\t\t<label>" . $row['label'] . "</label>\n"; $xml_output .= "\t\t<icon>" . $row['icon'] . "</icon>\n"; $xml_output .= "\t\t<url>" . $row['url'] . "</url>\n"; $xml_output .= "\t</link>\n"; } $xml_output .= "</links>"; echo $xml_output; ?> Link to comment https://forums.phpfreaks.com/topic/199955-whats-wrong-with-this-code/ Share on other sites More sharing options...
leehanken Posted April 27, 2010 Share Posted April 27, 2010 Code looks okay. Does it work if you say header("Content-type: text/html") so you can see the output?, or using a different browser? Link to comment https://forums.phpfreaks.com/topic/199955-whats-wrong-with-this-code/#findComment-1049563 Share on other sites More sharing options...
jimmyoneshot Posted April 27, 2010 Author Share Posted April 27, 2010 It say's "data not found". I forgot to mention it also says this if I output it as xml. I need to output it as xml as it's for use with a flex project which needs it to be xml so it can read the data from the output. The userid is submitted from my flex project to the php file then it SHOULD do thsi:- - Select all the records from the linkid column in which the userid column is equal to the submitted userid from flex:- $userlinks = "SELECT linkid FROM userlinks WHERE userid = '$param_userid' AND favourited = 'N'"; - Select all records from all columns in the links table in which the linkids match the ones that I've just got in $userlinks $query = "SELECT * FROM links WHERE linkid = '$userlinks' ORDER BY label ASC"; Am I doing something wrong there? Link to comment https://forums.phpfreaks.com/topic/199955-whats-wrong-with-this-code/#findComment-1049608 Share on other sites More sharing options...
jimmyoneshot Posted April 27, 2010 Author Share Posted April 27, 2010 Can anyone please give me a hint on this even if it's just to pop in and say that I'm an idiot or something? I'm a flex uni student but need to populate my app with data via php. I'm totally useless at php. Surely this is like abc compared to some of the stuff you guys see here. Please? Link to comment https://forums.phpfreaks.com/topic/199955-whats-wrong-with-this-code/#findComment-1049624 Share on other sites More sharing options...
jimmyoneshot Posted April 28, 2010 Author Share Posted April 28, 2010 Still can't figure out what's wrong here. Link to comment https://forums.phpfreaks.com/topic/199955-whats-wrong-with-this-code/#findComment-1049778 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.