Jump to content

What's Wrong With This Code?


jimmyoneshot

Recommended Posts

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

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?

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?  :shrug: 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?  :(

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.