I have found the problem for this page. I had not entered a categoryID in the database. Duh!!!
My website will not list all products on the screen. It only lists the first six. If someone has the time could you look at my code and tell me where my problem is. I certainly did not purposely ask it to only show six. Perhaps I have to add something to have it show all. I did try the * in my sql code but that just came back with an error. It is doing it on a delete a product page too, I am assuming the fix will be similar.
Maybe I have to add some html in there somewhere. Your advice will be appreciated.
Code is:
<?php
define('ALLOW_ACCESS', 1);
$title = 'Update a product';
require('../../incAdmin/incHead.php');
require_once('../../incAdmin/adminConnect.php');
?>
<h2>Choose the product you wish to update:</h2>
<?php
if ($_SESSION['loggedIn']) {
if (isset($_POST['cmdSubmit'])) {
// Check if a radio button has been selected
$message = '';
if (empty($_POST['rdoChooseRec'])) {
$message = 'ERROR: Please choose a product';
}
// If no errors, REDIRECT to updateAction.php
if ($message == '') {
$_SESSION['updateID'] = $_POST['rdoChooseRec'];
// start defining the URL
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// check for trailing slash
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
$url = substr($url, 0, -1); // get rid of slash
}
// add the page name and create the header
$url .= '/updateAction.php';
header("Location: $url");
exit(0);
}
}
else { // this is the first time form will be displayed. Initialise variable
$message = '';
$_SESSION['updateID'] = '';
}
?>
<form id="frmUpdateProduct" method="post" action="updateProduct.php">
<p><br />
<input type="submit" name="cmdSubmit" id="cmdSubmit" value="Proceed to EDIT screen" />
<span style="color:#F00;"><?php print $message; ?></span>
<br /><br />
<?php
// set up the SQL query
$sql = 'SELECT p.pImage, p.productID, c.cName, p.pName, p.pPrice FROM category as c, products as p WHERE c.categoryID = p.productID';
$stmt = $db->prepare($sql);
// Execute the statement
$stmt->execute();
// Bind PHP variables to the output from the prepared statement
$stmt->bind_result($pImage, $productID, $cName , $pName, $pPrice);
// Set up the table headings
print '<table width="70%">';
print '<tr><th> </th>';
print '<th class="leftText">Category</th>';
print '<th class="leftText">Product ID</th>';
print '<th class="leftText">Product Name</th>';
print '<th class="leftText">Image name</th>';
print '<th class="rightText">Price</th></tr>';
// Fetch and display the output
while ($stmt->fetch()) {
print "\n<tr>";
print '<td>';
print '<input type="radio" name="rdoChooseRec" id="rdoChooseRec" value="' . $productID . '" />';
print '</td>';
print '<td>';
print $cName;
print '</td>';
print '<td>';
print $productID;
print '</td>';
print '<td>';
print $pName;
print '</td>';
print '<td>';
print $pImage;
print '</td>';
print '<td class="rightText">';
printf("%0.2f", $pPrice); // format price to 2 decimal places
print '</td>';
print '</tr>';
}
// Close the statement
$stmt->close();
?>
</table>
</p>
</form>
<!----------------------------------------------------------------------------->
<?php
}
else {
print 'ERROR: you are not authorised to access this page';
}
require('../../incAdmin/incFoot.php');