Hi I have wrote a code to generate rss feed by a php script It works fine on localhost, but when uploaded to the server, it sends this error: Parse error: syntax error, unexpected T_STRING in /path_to_directory/rss_feed.php on line 12 As you see line 12 is: <?xml version="1.0" encoding="ISO-8859-1" ?> Code (markup): This is the script itself: <?php session_start(); require("dbconnect.php"); if(!isset($_SESSION['usertype'])) { header("Location: login.php"); } else { header("Content-Type: application/xml; charset=ISO-8859-1"); ?> <?xml version="1.0" encoding="ISO-8859-1" ?> <rss version="2.0"> <channel> <title>page title</title> <link>page link</link> <?php $result=mysql_query("SELECT * FROM feed ORDER BY id DESC LIMIT 20 "); while($row=mysql_fetch_array($result)){ //there are some more code here $item="<item> <title>$title</title> <link>$link</link> <description>$desc</description> </item>"; echo $item; } } ?> </channel> </rss> PHP: Thank you very much for your help
It is because the symbols "<?" is told the server that php script start. Change the script to: <?php session_start(); require("dbconnect.php"); if(!isset($_SESSION['usertype'])) { header("Location: login.php"); } else { header("Content-Type: application/xml; charset=ISO-8859-1"); echo('<?xml version="1.0" encoding="ISO-8859-1" ?> <rss version="2.0"> <channel> <title>page title</title> <link>page link</link>'); $result=mysql_query("SELECT * FROM feed ORDER BY id DESC LIMIT 20 "); while($row=mysql_fetch_array($result)){ //there are some more code here $item="<item> <title>$title</title> <link>$link</link> <description>$desc</description> </item>"; echo $item; } } ?> </channel> </rss> PHP:
<?php session_start(); require("dbconnect.php"); if(!isset($_SESSION['usertype'])): header("Location: login.php"); else: header("Content-Type: application/xml; charset=ISO-8859-1"); ?> <?xml version="1.0" encoding="ISO-8859-1" ?> <rss version="2.0"> <channel> <title>page title</title> <link>page link</link> <items> <?php $result=mysql_query("SELECT * FROM feed ORDER BY id DESC LIMIT 20 "); while($row=mysql_fetch_array($result)){ //there are some more code here $item="<item> <title>$title</title> <link>$link</link> <description>$desc</description> </item>"; echo $item; } // End While ?> </items> </channel> </rss> <?php endif;?> PHP:
<?php session_start(); require("dbconnect.php"); if(!isset($_SESSION['usertype'])) { header("Location: login.php"); } else { header("Content-Type: application/xml; charset=ISO-8859-1"); echo '<?xml version="1.0" encoding="ISO-8859-1" ?>'; ?> <rss version="2.0"> <channel> <title>page title</title> <link>page link</link> <?php $result=mysql_query("SELECT * FROM feed ORDER BY id DESC LIMIT 20 "); while($row=mysql_fetch_array($result)){ //there are some more code here $item="<item> <title>$title</title> <link>$link</link> <description>$desc</description> </item>"; echo $item; } } ?> </channel> </rss> Code (php):