Website URL:
http://quickstock.free.nf/ch10/quick/pages/catalog.php
I have read all the articles in the knowledge base and similar topics. Couldn’t find the answer.
I am using the free hosting for the website and created a database to connect to my PHP script. That’s still possible in the free hosting, right? I’m not using any external application to fetch the data from the database.
I configured an “.inc” file with all the necessary data to connect to the database:
<?php
$dbLocation = "sql208.infinityfree.com";
$dbUsername = "if0_35696018";
$dbPassword = "XXXXXXXXXXXXX"; (not changed from original)
$dbName = "if0_35696018_quickstock";
?>
The “connectToDatabase.php” script makes the connection to the database:
<?php
include ("......inc"); //I won't disclose the path for the file, but it is right.
if (!isset($dbLocation))
{
echo "Database location is missing.<br>
Connection script now terminating.";
exit(0);
}
if (!isset($dbUsername))
{
echo "Database username is missing.<br>
Connection script now terminating.";
exit(0);
}
if (!isset($dbPassword))
{
echo "Database password is missing.<br>
Connection script now terminating.";
exit(0);
}
$db = mysqli_connect($dbLocation,
$dbUsername,
$dbPassword,
$dbName);
if (mysqli_connect_errno() || ($db == null))
{
printf("Database connection failed: %s<br>
Connection script now terminating.");
}
?>
There is a script for listing the category of products from the database on the final page, called “displayListOfCategories.php”:
<?php
$query = "SELECT * FROM Ref_Product_Categories
ORDER BY department_name DESC";
$categories = mysqli_query($db, $query);
$numRecords = mysqli_num_rows($categories);
$categoryCount = 0;
$currentDepartment = "";
echo
"<table><tr><td><ul>";
for ($i=1; $i<=$numRecords; $i++)
{
$row = mysqli_fetch_array($categories, MYSQLI_ASSOC);
if ($currentDepartment != $row['department_name'])
{
if ($currentDepartment != "") echo "</ol></li>";
if ($categoryCount > $numRecords/2)
{
echo "</ul></td>\r\n<td class='AlignToTop'><ul>";
$categoryCount = 0;
}
$currentDepartment = $row['department_name'];
echo "<li>$currentDepartment<ol>";
}
$prodCatCode = urldecode($row['product_category_code']);
$prodCatDesc = $row['product_category_description'];
$categoryURL = "pages/category.php?categoryCode=$prodCatCode";
echo "<li><a href='$categoryURL'>$prodCatDesc</a></li>\r\n";
$categoryCount++;
}
echo
"</ol></li></ul></td></tr></table>";
mysqli_close($db);
?>
And finally the last “catalog.php” page to display the product’s categories:
<?php
//catalog.php
include("../common/document_head.html");
?>
<body>
<header>
<?php
include("../common/banner.php");
include("../common/menus.html");
include("../scripts/connectToDatabase.php");
?>
</header>
<main>
<article class="CategoryList">
<h4 class="ProductHeader">Complete List of Product Categories</h4>
<?php
include("../scripts/displayListOfCategories.php");
?>
</article>
</main>
<footer>
<?php include("../common/footer_content.html"); ?>
</footer>
</body>
</html>
The funny thing is that I experimented with this same database in the localhost and it works. However the page uploaded to the server shows everything, except the data from the database. No errors are presented.
P.S.: There is no CSS style for this webpage yet.
Any ideas?
Thank you in advance!