silvercover Posted November 16, 2009 Share Posted November 16, 2009 Here is my code: <?php require_once("includes/rss_generator.inc.php"); $host = "localhost"; $dbusername = "un"; // database username $dbpass = "pass"; // database password $db_prefix = ""; // tables prefix $dbtable = "table_name"; // database name $site = "http://www.site.com"; // shop url if (isset($_GET["noi"]) && !empty($_GET["noi"])){ $items_to_show = (int)$_GET["noi"]; // number of products to show in RSS }else{ $items_to_show = 10; } if (isset($_GET["rsscat"]) && !empty($_GET["rsscat"])){ $category = (int)$_GET["rsscat"]; // put category ID to show its items }else{ $category = 15; } $link = mysql_connect($host, $dbusername, $dbpass); if (!$link) { die('Could not connect: ' . mysql_error()); }else{ $db_selected = mysql_select_db($dbtable, $link); if ($db_selected){ // call RSS function showRSS($items_to_show, $category); }else{ die ('Can\'t use database: ' . mysql_error()); } } function showRSS($items, $cat){ global $link; global $db_prefix; global $site; $product_table = $db_prefix."_products"; $category_table = $db_prefix."_categories"; $rss_channel = new rssGenerator_channel(); $rss_channel->atomLinkHref = ""; $rss_channel->title = "Shopema.com RSS Feed"; // put your site title here $rss_channel->link = "http://www.shopema.com"; $rss_channel->description = "Shopema eShop"; // put your site description here $rss_channel->language = "fa"; $rss_channel->generator = "http://www.shopema.com"; $rss_channel->managingEditor = "[email protected]"; // put your email here $rss_channel->webMaster = "[email protected]"; // put your email here $query =" SELECT * FROM ". $product_table; $query .=" WHERE categoryID = ". $cat ." ORDER BY productID DESC LIMIT 0 , ".$items; $result = mysql_query($query); while ($row = mysql_fetch_assoc($result)) { $item = new rssGenerator_item(); $item->title = $row['name']; $item->description = $row['description']; $item->link = $site."/index.php?productID=".$row['productID']; $item->guid = $site."/index.php?productID=".$row['productID']; $item->pubDate = date("D, d M Y H:i:s O"); $rss_channel->items[] = $item; } $rss_feed = new rssGenerator_rss(); $rss_feed->encoding = 'UTF-8'; $rss_feed->version = '2.0'; header('Content-Type: text/xml'); echo $rss_feed->createFeed($rss_channel); } ?> It's job is to fetch items from database and generate RSS feed. it works perfect on localhost running WAMP. but when I upload it and test it, it seems while loop doesn't work at all! I'm sure I've set uppers variable with correct values and so for this forum I've changed real values. I should say that I've used rss_generator.inc.php several times before and It works perfect on the other projects. What's wrong? Thanks Link to comment https://forums.phpfreaks.com/topic/181770-solved-whats-wrong-with-this-code/ Share on other sites More sharing options...
mrMarcus Posted November 16, 2009 Share Posted November 16, 2009 you have: LIMIT 0 in your SQL statement. Link to comment https://forums.phpfreaks.com/topic/181770-solved-whats-wrong-with-this-code/#findComment-958650 Share on other sites More sharing options...
Vebut Posted November 16, 2009 Share Posted November 16, 2009 Your 'where' clause has no "single quote: ' " wrappers on the category id. And it is not escaped so this function is a major security risk. Have a look ad mysql_real_escape_string function @php.net Without an error message its hard to pinpoint the origin of your problem. Do you have rows in the "public" database? Link to comment https://forums.phpfreaks.com/topic/181770-solved-whats-wrong-with-this-code/#findComment-958655 Share on other sites More sharing options...
silvercover Posted November 16, 2009 Author Share Posted November 16, 2009 Yes i have rows in pubic database and I did escaping in real script. I've tried to make this as simple as I could to track down the problem. I've also quoted where clause and nothing happened! I tried to set my server shows every php errors but still no clues! Thanks in Advance. Link to comment https://forums.phpfreaks.com/topic/181770-solved-whats-wrong-with-this-code/#findComment-958680 Share on other sites More sharing options...
Vebut Posted November 16, 2009 Share Posted November 16, 2009 Try using var_dump() on the $row variable inside of the while loop to see what it contains. Link to comment https://forums.phpfreaks.com/topic/181770-solved-whats-wrong-with-this-code/#findComment-958684 Share on other sites More sharing options...
mrMarcus Posted November 16, 2009 Share Posted November 16, 2009 did you change LIMIT 0 to LIMIT 1 (at least 1 .. the number is up to you)? add: or trigger_error (mysql_error()) to: $result = mysql_query($query) or trigger_error(mysql_error()); and change your WHERE to: WHERE categoryID = '". $cat ."' Link to comment https://forums.phpfreaks.com/topic/181770-solved-whats-wrong-with-this-code/#findComment-958687 Share on other sites More sharing options...
Vebut Posted November 16, 2009 Share Posted November 16, 2009 mrMarcus: LIMIT 0, X will limit the results to a certain amount of posts. It works just like LIMIT X. Link to comment https://forums.phpfreaks.com/topic/181770-solved-whats-wrong-with-this-code/#findComment-958693 Share on other sites More sharing options...
mrMarcus Posted November 16, 2009 Share Posted November 16, 2009 wow, i didn't even notice the $items at the end there. think i'm done for the day Link to comment https://forums.phpfreaks.com/topic/181770-solved-whats-wrong-with-this-code/#findComment-958703 Share on other sites More sharing options...
silvercover Posted November 16, 2009 Author Share Posted November 16, 2009 I've found damn problem. it was because of some special HTML characters in description field and therefor RSS was not valid. so I used htmlspecialchars and fortunately it worked! Thank you. Link to comment https://forums.phpfreaks.com/topic/181770-solved-whats-wrong-with-this-code/#findComment-958705 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.