Thanks for the reply,
I think you misunderstood my code. The following code in the controller file is the code that queries the database and then at the end it includes categories.html.php which outputs the categories to the browser:
// Display category list
include $_SERVER['DOCUMENT_ROOT'] . '/includes/dbAdmin.inc.php';
$result = mysqli_query($link, 'SELECT catID, category FROM categories');
if (!$result)
{
$error = 'Error fetching categories from database!';
include 'error.inc.html.php';
exit();
}
while ($row = mysqli_fetch_array($result))
{
$categories[] = array('catID' => $row['catID'], 'category' => $row['category']);
}
if (!isset($_SESSION['category']) || empty($_SESSION['category']))
{
$_SESSION['category'] = $row['category'];
}
include 'categories.html.php';
?>
The following code is the contents of categories.html.php
<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/helpers.inc.php'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Manage Categories</title>
<meta http-equiv="content-type"
content="text/html; charset=utf-8"/>
</head>
<body>
<h1>Manage Categories</h1>
<p><a href="?add">Add new category</a></p>
<ul>
<?php foreach ($categories as $category): ?>
<li>
<form action="" method="post">
<div>
<?php htmlout($category['category']); ?>
<input type="hidden" name="catID" value="<?php
echo $category['catID']; ?>"/>
<input type="submit" name="action" value="Edit"/>
<input type="submit" name="action" value="Delete"/>
</div>
</form>
</li>
<?php endforeach; ?>
</ul>
</body>
</html>
The above code displays the categories and has a delete and edit button next to each category. I need to capture the value of the category that is clicked on when a user presses the delete button as I need this value in the third page called category_delete_html.php as follows:
<?php include_once $_SERVER['DOCUMENT_ROOT'] . '/includes/helpers.inc.php'; ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Manage Categories</title>
<meta http-equiv="content-type"
content="text/html; charset=utf-8"/>
</head>
<body>
<h1>Delete Category</h1>
<p>
<?php
if ($recordsExist) {
print_r($_SESSION);
echo '<p class="warning">'. $_SESSION['category'] . ' category has dependent records. Can\'t be deleted.</p>';
}
else {
?>
</p>
<p class="warning">Please confirm that you want to delete the following record. This operation cannot be undone. </p>
<p><a href="?add">Add new category</a></p>
<ul>
<li>
<form action="" method="post">
<div>
<?php htmlout($category['category']); ?>
<input type="hidden" name="catID" value="<?php
echo $category['catID']; ?>"/>
<input type="submit" name="delete" value="Confirm deletion"/>
</div>
</form>
</li>
</ul><?php } ?>
</body>
</html>
It's in this delete page where I'm trying to ouput the value of the category as in the following code:
<?php
if ($recordsExist) {
print_r($_SESSION);
echo '<p class="warning">'. $_SESSION['category'] . ' category has dependent records. Can\'t be deleted.</p>';
}
else {
?>
</p>
So my original question is still not answered. I'm trying to capture the value of the category that was clicked on in the page that lists the categories. To clarify it's not the id I'm trying to capture eg. $_POST['catID'] - it's the category, ie.
<?php htmlout($category['category']); ?>
Any further advice appreciated.