Help with inherited database site

Hope someone can help with this, although I might be a bit vague. (But will be happy to post any code that might help.)

Basically I do a few sites for a company, and everything is coming together nicely moving everything to a new reseller hosting account where everything can site. I’m basically doing some redesign and new database work for them.

But there’s one site I’m basically just trying to move over, that already has a database. I’ve copied the site onto the new hosting, copied the database across and created a new connection file.

I must admit the code is all a bit more PHPO heavy than what I’m used to working with. so have run into a problem trying to figure out what data is not displaying due to queries failing. As far as I can tell the connection is working, and the queries have not changed.

Anyway - the main page is here, where you should be able to click on the furniture images to go to the product page :

http://www.miradatravelmedia.com/lusty/public_html/index.php

But when you click through the product page query is failing :

http://www.miradatravelmedia.com/lusty/public_html/products.php?category=1

The products page is mostly PHP and looks like this :

<?php
if (!@empty($_REQUEST["img"])) {
  require_once("../includes/hft_image.php");
  $img = new hft_image($_REQUEST["img"]);
  $img->resize(200,180,"-");
  $img->output_resized("");
  exit;
}
$page = "products";
include("../includes/header.php");
include("../includes/db_open.php");
$sql = "SELECT `id`, `name` FROM `categories` WHERE `id` = '" . $_REQUEST["category"] . "'";
$result = mysql_query($sql) or die("Query failed : $sql at line " . __line__);
$category = mysql_fetch_assoc($result);
?>
<div id="trail"><a href="shop.php">Shop</a> > Lloyd Loom <?php echo $category["name"]?></div>
  <div class="clear" id="divider1"><img src="images/spacer.gif" alt="<?php echo keyword()?>" /></div>
  
<h1>Lloyd Loom <?php echo $category["name"]?></h1>
<?php
$sql =
  "SELECT * " .
  "FROM `products` " .
  "WHERE `category` = '" . $_REQUEST["category"] . "' " .
  "ORDER BY `order`";
$result = mysql_query($sql) or die("Query failed : $sql at line " . __line__);
if (mysql_num_rows($result) == 0) {
?>
<p>Coming soon ...</p>
<?php
} else {
  $n = 0;
  while ($row = mysql_fetch_assoc($result)) {
    $n++;
?>
<a href="product.php?id=<?php echo $row["id"]?>" class="product"<?php if ($n == mysql_num_rows($result)) echo " id=\\"last\\""?>>
<?php
    if ($file = glob("images/products/" . $row["id"] . "_*.*")) {
?>
<img src="img.php?img=<?php echo $file[0]?>&width=200&height=180" alt="<?php echo $row["code"]?>" />
<?php
    } else {
?>
<div id="no_image">No image found</div>
<?php
    }
?>
<?php echo $row["code"]?>
</a>
<?php
    if (is_int($n / 4)) {
?>
<div class="clear"><img src="images/spacer.gif" alt="<?php echo keyword()?>" /></div>
<?php
    }
  }
}
?>
  <div class="clear" id="divider2"><img src="images/spacer.gif" alt="<?php echo keyword()?>" /></div>
<?php
include("../includes/footer.php");
?>

If anyone could shed any light on what’s going wrong still, that would be much appreciated.

Thanks.

 
$sql = "SELECT `id`, `name` FROM `categories` WHERE `id` = '" . $_REQUEST["category"] . "'"; 
 
[COLOR=red]echo $sql; die();[/COLOR]

The red code will terminate your script execution and display in your browser the query about to be run ($sql).

Make sure that the query is what it’s supposed to be both in content and syntax.

You can use the ‘echo’ command to also display values of other variables throughout the code as part of your debugging of the script.

Where should I put that code exactly? I put it in near the bottom of that page before the footer, but it didn’t seem to do anything.

Its a bit frustrating, as I hoped it would be fairly straightforward to simply move the site to a new host server - move site files across, export / import database and change the connection details.

It all seems to work with the same code on the original site, which is still live here :

http://www.lloydloomonline.com/

OK - thanks for taking a look.

It just seems odd that its the same code, just on a different hosting server, but isn’t working.

I got to the bottom of it - the issue was with the syntax in the connection file, not the query.

ok, then that means that particular query is working ok.

You now need to check the other queries in that script in the same way.

If you find that after echoing the queries, they are all ok then that means the problem is elsewhere in the script and since I can’t run your actual code, all I can suggest is you check the values of all the other variables in your script to make sure they are correct.

When you find the query or variable that is incorrect, back track the code to find the source of the problem.

if the queries are failing, the first thing I would suggest to do is insert

 
echo $sql; die();

after a query and make sure it looks correct.

If it isn’t then back track the code to find the source of the incorrect parameter being inputed into the query.

OK - that looks about right - it displays :

SELECT id, name FROM categories WHERE id = ‘1’

http://www.miradatravelmedia.com/lusty/public_html/products.php?category=1

Which is what I’d expect.

I dropped that die line into the original site’s equivalent page, and it matched OK.

So again, it seems odd that the query is fine on the page on the original server, but going wrong when copied across.