Jump to content

[SOLVED] What's wrong with this code?


silvercover

Recommended Posts

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@email.com";      // put your email here
  $rss_channel->webMaster      = "email@email.com";      // 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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.