Script works on IIS not on Remote Server

A

Anonymous

Guest
I wrote and tested my script on a server using IIS, PHP 4.1.1, and MySQL version 1.4. I uploaded my script to my remote server which uses Apache, PHP 4.3.8 and MySQL version 4.0.20. Both of my databases are identical, so that is not the issue. When I try to run this script on my remote server I get:

"You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'ORDER BY item_title DESC limit 20' at line 1"

Here is my code:

Code:
<?php
//connect to database
$conn = mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("mass",$conn)  or die(mysql_error());

$display_block = "<P></p>";

//validate subcats
$get_subcats = "SELECT c.cat_title, s.subcat_title FROM subcategories as s left join categories as c on c.id = s.cat_id WHERE s.id = $_GET[subcat_id]";
$get_subcats_res = mysql_query($get_subcats) or die (mysql_error());

if (mysql_num_rows($get_subcats_res) < 1) {
   //invalid subcats
   $display_block .= "<P><em></em></p>";
} else {
   //valid subcats, get items
   $cat_title = stripslashes(mysql_result($get_subcats_res,0,'cat_title'));
   $subcat_title = stripslashes(mysql_result($get_subcats_res,0,'subcat_title'));

   //make breadcrumb trail
   $display_block .= "<P><strong>$cat_title > $subcat_title</strong></p>";

   //get items
$get_items = "SELECT id, item_title, item_image, item_price FROM productinfo WHERE subcat_id = $subcat_id ORDER BY item_title DESC limit 20";
   $get_items_res = mysql_query($get_items) or die(mysql_error());

   if (mysql_num_rows($get_items_res) > 0) {
   
        $display_block .= "<P><strong></strong><br>";
		
		while ($items = mysql_fetch_array($get_items_res)) {
           $item_title = $items['item_title'];
		   $item_id = $items['id'];
		   $item_price = $items['item_price'];
		   $item_image = $items['item_image'];
		   
           $display_block .= "<P></p>
	<table cellpadding=3 cellspacing=3>
   <tr>
   <td valign=middle align=center><P><a href=\"showitem.php?item_id=$item_id\" target=\"mainFrame\"><img src=\"$item_image\" border=\"0\" width=\"50\" height=\"50\"><br>$item_title</a><br>\$$item_price</p>";
       }
   }

   $display_block .= "
   </td>
   </tr>
   </table>";
}
?>
<html>
<head>
<title>Martial Art Supply Store</title></head>
<body>
     <? print $display_block; ?>
</body>
</html>

Here is the code from the page that links to the above code:

Code:
<?php
//connect to database
$conn = mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("mass",$conn)  or die(mysql_error());

$display_block = "<P></p>";

//show categories first
$get_cats = "select id, cat_title from categories order by cat_title";
$get_cats_res = mysql_query($get_cats) or die(mysql_error());

if (mysql_num_rows($get_cats_res) < 1) {
   $display_block = "<P><em>Sorry, no categories to browse.</em></p>";
} else {
   while ($cats = mysql_fetch_array($get_cats_res)) {
        $cat_id  = $cats['id'];
        $cat_title = stripslashes($cats['cat_title']);

        $display_block .= "<p><strong><a href=\"$_SERVER[PHP_SELF]?cat_id=$cat_id\">$cat_title</a></strong></p>";

        if ($_GET['cat_id'] = $cat_id) {
           //get subcats
           $get_subcats = "select id, subcat_title from subcategories where cat_id = $cat_id order by subcat_title";
           $get_subcats_res = mysql_query($get_subcats) or die(mysql_error());

           if (mysql_num_rows($get_subcats_res) < 1) {
                $display_block = "<P><em>no subcategories</em></p>";
           } else {
                $display_block .= "<ul>";

                while ($subcats = mysql_fetch_array($get_subcats_res)) {
                   $subcat_id  = $subcats['id'];
                   $subcat_title = stripslashes($subcats['subcat_title']);

                   $display_block .= "<li><a href=\"showsubcat.php?subcat_id=$subcat_id\" target=\"mainFrame\">$subcat_title</a></strong>";
                }

                $display_block .= "</ul>";
           }
       }
   }
}
?>
<HTML>
<HEAD>
<TITLE>Martial Art Supply Store</TITLE>
<style type="text/css">

</style>
</HEAD>
<BODY>
<div class="style1"><? print $display_block; ?></div>
</BODY>
</HTML>
 
try replacing
$get_items = "SELECT id, item_title, item_image, item_price FROM productinfo WHERE subcat_id = $subcat_id ORDER BY item_title DESC limit 20";

with

$get_items = "SELECT id, item_title, item_image, item_price FROM productinfo WHERE subcat_id = '$subcat_id' ORDER BY item_title DESC limit 20";

Andrew
 
Well, that solved the problem of the error message. Now my breadcrumb trail shows also. However, the products are still not showing up. And I know that it's not a problem with the database or product table because they show up on my home page when i search for only the products WHERE sale = 'y'.
 
I can't see that query anywhere in your posted code... can you post a copy of that?

Andrew
 
Here is the code with that query in it, but it's a different page. I was just saying that I know it's not the database because my other pages work.

Code:
<?php
//connect to database
$conn = mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("mass",$conn)  or die(mysql_error());

$display_block = "<P></p>";

//get items
   $get_items = "select id, item_title, item_image, item_price, item_desc from productinfo where sale = 'y' order by item_title";
   $get_items_res = mysql_query($get_items) or die(mysql_error());

   if (mysql_num_rows($get_items_res) > 0) {
        $display_block .= "<P><strong></strong><br>";
        while ($items = mysql_fetch_array($get_items_res)) {
		   $item_id = $items['id'];
           $item_title = $items['item_title'];
		   $item_price = $items['item_price'];
		   $item_image = $items['item_image'];
		   
           $display_block .= "<P></p>
	<table cellpadding=3 cellspacing=3>
   <tr>
   <td valign=middle align=center><P><a href=\"showitem.php?item_id=$item_id\" target=\"mainFrame\"><img src=\"$item_image\" border=\"0\" width=\"50\" height=\"50\"><br>$item_title</a><br>\$$item_price</p>";
       }
   }

   $display_block .= "
   </td>
   </tr>
   </table>";
?>
 
Back
Top