shane85 Posted August 16, 2009 Share Posted August 16, 2009 I have this rss file that works perfectly however I put in an IF statement so that if the row ticker in my database is empty, I dont want it to display the rss page, rather just die and display txt saying "ticker is empty or not set" what happens when the if statement is in is it doesnt display the rss page, it says ------------------ The XML page cannot be displayed Cannot view XML input using style sheet. Please correct the error and then click refresh button, or try again later. Invalid at the top level of the document. Ticker is empty or not set ^ ------------------ however, the row ticker in my database is not empty and does have text. when I remove the if statement, it works perfectly. The php file is as follows <?php header('Content-type: application/xml'); $dbhost = 'localhost'; $dbuser = 'username'; $dbpass = 'password'; $dbname = 'name'; // make a connection to mysql here $conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ("I cannot connect to the database because: " . mysql_error()); mysql_select_db ($dbname) or die ("I cannot select the database '$dbname' because: " . mysql_error()); If (empty($ticker)){ die("Ticker is empty or not set"); //Display an error and kill page. } else { // begin to display the rss for the if statement echo "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n"; echo "<channel>\n"; echo "<title>RSS Feed</title>\n"; echo "<link>http://www.website.ca</link>\n"; $result = mysql_query("SELECT location_id, ticker FROM host_locations WHERE location_id='2'")or die(mysql_error()); while ($row = mysql_fetch_object($result)) { echo "<item>\n"; echo "<title>$row->ticker</title>\n"; echo "<description></description>\n"; echo "<pubDate></pubDate>\n"; echo "<link>http://www.website.ca/testing/rss/test.php?post=$row->location_id</link>\n"; echo "<atom:link href=\"http://www.website.ca/testing/rss/test.php?post=$row->location_id\" rel=\"self\" type=\"application/rss+xml\"/>\n"; echo "</item>\n"; } echo "</channel>\n"; echo "</rss>\n"; } // end the if statement for ticker ?> again, if I remove everything to do with that IF statement, it displays the rss page correctly without any problems Link to comment https://forums.phpfreaks.com/topic/170569-sorry-to-repostbut-having-problem-with-if-statement-in-rss-file/ Share on other sites More sharing options...
Simon Mayer Posted August 17, 2009 Share Posted August 17, 2009 I'm not sure, but I think you need to move this line of code into your else statement. I think it causes problems with the error message: header('Content-type: application/xml'); Link to comment https://forums.phpfreaks.com/topic/170569-sorry-to-repostbut-having-problem-with-if-statement-in-rss-file/#findComment-899843 Share on other sites More sharing options...
trq Posted August 17, 2009 Share Posted August 17, 2009 $ticker isn't defined anywhere in your script. Link to comment https://forums.phpfreaks.com/topic/170569-sorry-to-repostbut-having-problem-with-if-statement-in-rss-file/#findComment-899847 Share on other sites More sharing options...
shane85 Posted August 17, 2009 Author Share Posted August 17, 2009 sorry to ask such a newbie question I just cant think right now....how would I define it ??? its in the table host_locations and the row is called ticker ... normally on my pages I have a session created and I use $ticker= $_SESSION["SESS_TICKER"]; but im not using a session on this page...this one will be strictly so that the software can point to it Link to comment https://forums.phpfreaks.com/topic/170569-sorry-to-repostbut-having-problem-with-if-statement-in-rss-file/#findComment-899852 Share on other sites More sharing options...
shane85 Posted August 17, 2009 Author Share Posted August 17, 2009 CHANGE OF APPROACH im trying something different, which is loading the rss page, however not exiting when there is no data in the row ticker in the database...whats wrong...heres the lowerhalf of the code without the databse connectino details. What I am trying is if(@mysql_num_rows($result)==0){ die('No data available'); } but do I have to identify the ticker row in that statement? What im trying to say is if the ticker row is blank, dont load the page! // make a connection to mysql here $conn = mysql_connect ($dbhost, $dbuser, $dbpass) or die ("I cannot connect to the database because: " . mysql_error()); mysql_select_db ($dbname) or die ("I cannot select the database '$dbname' because: " . mysql_error()); $result = mysql_query("SELECT location_id, ticker FROM host_locations WHERE location_id='2'")or die(mysql_error()); if(@mysql_num_rows($result)==0){ die('No data available'); } header('Content-type: application/xml'); echo "<rss version=\"2.0\" xmlns:atom=\"http://www.w3.org/2005/Atom\">\n"; echo "<channel>\n"; echo "<title>RSS Feed</title>\n"; echo "<link>http://www.website.ca</link>\n"; while ($row = mysql_fetch_object($result)) { echo "<item>\n"; echo "<title>$row->ticker</title>\n"; echo "<description></description>\n"; echo "<pubDate></pubDate>\n"; echo "<link>http://www.website.ca/testing/rss/test.php?post=$row->location_id</link>\n"; echo "<atom:link href=\"http://www.website.ca/testing/rss/test.php?post=$row->location_id\" rel=\"self\" type=\"application/rss+xml\"/>\n"; echo "</item>\n"; } echo "</channel>\n"; echo "</rss>\n"; Link to comment https://forums.phpfreaks.com/topic/170569-sorry-to-repostbut-having-problem-with-if-statement-in-rss-file/#findComment-899866 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.