Hi everyone,
I have the following link on a page in my site:
<a href="index.php?subcatID=1&itemTypeID=3">
The link is carrying two variable/value pairs and points to a controller file.
The value of the variables are captured via the following code block in the controller file:
if (isset ($_GET['subcatID']) && ($_GET['itemTypeID'])) {
include_once(__ROOT__ . "/includes/db.inc.php");
$subcatID = mysqli_real_escape_string($link, $_GET['subcatID']);
$itemTypeID = mysqli_real_escape_string($link, $_GET['itemTypeID']);
The value of the $itemTypeID variable is used in the following WHERE clause in the sql query:
WHERE itemTypes.itemTypeID="$itemTypeID"'
When I test however, the browser isn't outputting anything. Although if I change the WHERE clause to the following it outputs everything correctly:
WHERE itemTypes.itemTypeID=3
It seems that for some reason it's not recognizing the value of the $itemTypeID variable.
The following is the full code in the controller:
<?php
if ($_SERVER['HTTP_HOST'] != "new_site.com") {
define ('__ROOT__', $_SERVER['DOCUMENT_ROOT'] . '/new_site');
} else {
define ('__ROOT__', $_SERVER['DOCUMENT_ROOT']);
}
include_once(__ROOT__ . "/includes/magicquotes.inc.php");
if (isset ($_GET['subcatID']) && ($_GET['itemTypeID'])) {
include_once(__ROOT__ . "/includes/db.inc.php");
$subcatID = mysqli_real_escape_string($link, $_GET['subcatID']);
$itemTypeID = mysqli_real_escape_string($link, $_GET['itemTypeID']);
$select = 'SELECT
items.itemID,
itemTitle,
itemSKULadies,
itemSKUMen,
itemDescLadies,
itemDescMen,
itemPriceBoth,
itemPriceFemale,
itemPriceMale,
itemColoursBoth,
itemColoursFemale,
itemColoursMale,
itemTypes.itemType,
subcategories.subcategory,
sizesMen.size AS Msize,
sizesLadies.size AS Lsize,
itemSwatchBoth,
itemSwatchFemale,
itemSwatchMale,
itemImage';
$from = ' FROM items
LEFT JOIN sizesMen ON sizesMen.sizeMenID=items.sizeMenID
LEFT JOIN sizesLadies ON sizesLadies.sizeLadiesID=items.sizeLadiesID
LEFT JOIN itemTypes ON itemTypes.itemTypeID=items.itemTypeID
LEFT JOIN item_to_subcat ON item_to_subcat.itemID = items.itemID
LEFT JOIN subcategories ON subcategories.subcatID = item_to_subcat.subcatID ';
$where = ' WHERE itemTypes.itemTypeID="$itemTypeID"';
$result = mysqli_query($link, $select . $from . $where);
if (!$result)
{
$error = 'Error fetching items: ' . mysqli_error($link);
include 'error.html.php';
exit();
}
$items = array();
while ($row = mysqli_fetch_array($result))
{
$items[] = array('itemTitle' => $row['itemTitle'], 'itemSKULadies' => $row['itemSKULadies'], 'itemSKUMen' => $row['itemSKUMen'], 'itemDescLadies' => $row['itemDescLadies'], 'itemDescMen' => $row['itemDescMen'], 'itemPriceBoth' => $row['itemPriceBoth'], 'itemPriceFemale' => $row['itemPriceFemale'], 'itemPriceMale' => $row['itemPriceMale'], 'itemColoursBoth' => $row['itemColoursBoth'], 'itemColoursFemale' => $row['itemColoursFemale'], 'itemColoursMale' => $row['itemColoursMale'], 'Lsize' => $row['Lsize'], 'Msize' => $row['Msize'], 'itemType' => $row['itemType'], 'itemSwatchBoth' => $row['itemSwatchBoth'], 'itemSwatchFemale' => $row['itemSwatchFemale'], 'itemSwatchMale' => $row['itemSwatchMale'], 'itemImage' => $row['itemImage']);
}
include 'catalogue.php';
exit();
}
?>
Does anyone know what might be happening?
Appreciate any help.