I'm new to PHP and I've read many of the other undefined index error solutions on stackoverflow, but I still can't figure out why this rather simple code is receiving it. There's data in the database and everything else is pulling ok.
Right now I'm just trying to make sure the function and query are flowing through properly. So I purposely don't have if statements to check and see if the items are selected on the form because I'm always selecting them during testing. I must be missing something simple. Please help and thank you!
Form:
<!DOCTYPE html>
<html>
<head><title>Databases</title></head>
<body>
<h1>Music Store Database</h1>
<form method='POST' action='display.php'
<label>Select a table:</label>
<select name="tableName">
<option value="products">Products</option>
<option value="categories">Categories</option>
</select>
<p>Retrieve Record(s) - Select field(s) below:</p>
<input type="checkbox" name="productIDcb"/>
<label>ProductID</label><br />
<input type="checkbox" name="categoryIDcb"/>
<label>CategoryID</label><br />
<input type="checkbox" name="productCodecb"/>
<label>Product Code</label><br />
<input type="checkbox" name="productNamecb"/>
<label>Product Name</label><br />
<input type="checkbox" name="listPricecb"/>
<label>List Price</label><br />
<input type="checkbox" name="categoryNamecb"/>
<label>Category Name</label><br />
.
.
.
<p>Select the appropriate action based on your selection from above:</p>
<input type="radio" name="operation" value="retrieve"/>
<label>Retrieve Information</label><br />
<input type="radio" name="operation" value="addition"/>
<label>Add Information</label><br />
<input type="radio" name="operation" value="delete"/>
<label>Delete Information</label><br />
<p><input type="submit" value="Submit Request"/></p>
display.php File
<?php
require('database.php');
require('product_list.php');
$table = $_POST['tableName'];
$operation = $_POST['operation'];
$productIDcb = $_POST['productIDcb'];
$categoryIDcb = $_POST['categoryIDcb'];
$productCodecb = $_POST['productCodecb'];
$productNamecb = $_POST['productNamecb'];
$listPricecb = $_POST['listPricecb'];
if($operation == 'retrieve')
{
if($table == "products")
{
include_once('product_list.php');
show_products($table, $productIDcb, $categoryIDcb, $productCodecb, $productNamecb, $listPricecb);
}
}
?>
product_list.php file
<?php
include('database.php');
function show_products($table, $productIDcb, $categoryIDcb, $productCodecb, $productNamecb, $listPricecb)
{
global $db;
$theQuery = "select productId, categoryID, productCode, productName, listPrice ";
$theQuery .=" from ". $table;
echo($theQuery);
$rSet = $db -> query($theQuery);
$list = "";
foreach($rSet AS $products)
{
$list .= "".$products['productID']
. "".$products['categoryID']
. "".$products['productCode']
. "".$products['productName']
. "".$products['listPrice']
. "<br>";
}
echo($list);
}
?>