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 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

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?

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.

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 ."'

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.