Why would duplicated code not work?
Not surprisingly I've managed to find myself stumped while working on another aspect of this same project that has had me occupied for the last month or so. What I can't figure out is why I should be having any trouble at all since the thing which is breaking is a copy of another part which is. Allow me to explain.
Working perfectly we have the database of products. On the page for displaying each of the product brands there is this bit of code that makes sure you are asking it to display a valid brand based on the link that sent you there (formatted like this: products_displayBrand.php?brand_id=1).
As I said, this is working just fine. Well now they're having me add a nearly identical feature for marketing materials and the like. So I have been working on duplicating the pages and their relevant code. This practice got me to here:
Everything looks right to me, but when you click on any of the links that bring you here (other_displayCategory.php?category_id=1) it rolls right over to the index page. It is supposed to do this if you have provided am incorrect category_id, but that isn't happening as near as I can tell.
So can anyone, looking at this, tell me what might be wrong with what I am doing and why it would be causing an error one way and not another? Thanks.
Working perfectly we have the database of products. On the page for displaying each of the product brands there is this bit of code that makes sure you are asking it to display a valid brand based on the link that sent you there (formatted like this: products_displayBrand.php?brand_id=1).
// Check for validity of value of brand
$chk_brand = "SELECT brand_id FROM $table_1 WHERE brand_id = '$brand_id'";
$chk_brand_res = @mysql_query($chk_brand, $connection) or die('Error: could not execute query. The following error was returned: '.mysql_error());
$chk_brand_num = mysql_num_rows($chk_brand_res);
// Deal with results of validation of id
if ($chk_brand_num == "0") {
header("Location: index.php");
exit;
} else {
$sql = "
SELECT brand_id, brand_name, brand_description, brand_image
FROM $table_1
WHERE brand_id = '$brand_id' || brand_name = '" . $_GET['brand_name'] . "'
";
$result = @mysql_query($sql, $connection) or die("Couldn't execute query.");
}As I said, this is working just fine. Well now they're having me add a nearly identical feature for marketing materials and the like. So I have been working on duplicating the pages and their relevant code. This practice got me to here:
// Check for validity of value of category
$chk_category = "SELECT category_id FROM $table_3 WHERE category_id = '$category_id'";
$chk_category_res = @mysql_query($chk_category, $connection) or die('Error: could not execute query. The following error was returned: '.mysql_error());
$chk_category_num = mysql_num_rows($chk_category_res);
// Deal with results of validation of id
if ($chk_category_num == "0") {
header("Location: index.php");
exit;
} else {
$sql = "
SELECT category_id, category_name, category_description
FROM $table_3
WHERE category_id = '$category_id' || category_name = '" . $_GET['category_name'] . "'
";
$result = @mysql_query($sql, $connection) or die("Couldn't execute query.");
}Everything looks right to me, but when you click on any of the links that bring you here (other_displayCategory.php?category_id=1)
So can anyone, looking at this, tell me what might be wrong with what I am doing and why it would be causing an error one way and not another? Thanks.
