My current program, for some reason, won't register my database values even though my previous code(looks identical but from different database tables) works just fine.
So far I have no errors when it runs. The only thing that prints for each page is the table's title. Also the clients page works just fine. So the product(tv, cell, computer) and transaction page are my current issue.
My current index.php file (main program) is as follows:
<?php
//url /index.php?action=clients
include('header.php'); // create top box
include('sidemenu.php'); // create side menu
//database connection
include('pdo_connect.php');
//Read data type
$type = "";
if (isset($_REQUEST['action']))
$type = $_REQUEST['action'];
//echo 'Action: {$type}';
switch($type) {
case 'products' : //display a list of clients
//define sql
$sql = "SELECT product_type, product_title, product_description, unit_price FROM products
WHERE product_type = :product_type";
$values = array(':product_type'=>$_GET['product_type']);
$products = getAll($sql);
//display result
displayProductList($products);
break;
case 'clients' : //displaya list of movies
$sql = "SELECT first_name, last_name, email FROM p_clients";
$clients = getAll($sql);
displayClientList($clients);
break;
case 'transactions' :
$sql = "SELECT products.product_title, products.product_description, products.unit_price, p_clients.first_name,
p_clients.last_name, sales.quantity FROM p_clients INNER JOIN sales, products ON p_clients.client_id = sales.client_id
AND products.product_id = sales.product_id";
$transactions = getAll($sql);
displayTransactionList($transactions);
break;
default:
defaultView();
break;
}
include('footer.php');
function defaultView() {
?>
<!-- add page content -->
<div id='content'>
<h2>Welcome to our movie store</h2>
</div>
<div id = 'image'></div>
<div id = 'box'>
<p id = 'text-box'>
We appreciate your interest in our products and services. Please reference
the the links provided to see our current specials for each of our clients.
</p>
</div>
<?php
}
function displayProductList($products) {
echo "<div id='content'>
<h2>List of Products</h2>";
echo "<table id = clients>";
echo "<tr><td id = 'title'>Product Name</td><td id= 'title'>Description</td><td id = 'title'>Cost</td></tr>";
//display each record
for ($i = 0; $i < count($products); $i++){
echo "<tr><td>{$products[$i]['product_title']} </td><td> {$products[$i]['product_description']} </td><td>
{$products[$i]['unit_price']} </td></tr>" ;
}
echo "</table>";
echo "</div>";
}
function displayClientList($clients) {
echo "<div id='content'>
<h2>List of Clients</h2>";
echo "<table id = 'long'>";
// echo "<table>";
echo "<tr><td id = 'title'>First Name</td><td id= 'title'>Last Name</td><td id = 'title'>Email</td></tr>";
//display each record
for ($i = 0; $i < count($clients); $i++){
echo "<tr><td>{$clients[$i]['first_name']}</td><td> {$clients[$i]['last_name']}
</td><td> {$clients[$i]['email']} </td></tr>";
}
echo "</table>";
echo "</div>";
}
function displayTransactionList($transactions) {
echo "<div id='content'>
<h2>List of Client Transactions</h2>";
echo "<table id = 'long'>";
// echo "<table>";
echo "<tr><td id = 'title'>First Name</td><td id= 'title'>Last Name</td><td id = 'title'>Product Title</td>
<td id = 'title'>Product Description</td><td id = 'title'>Cost</td><td id = 'title'>Quantity</td></tr>";
//display each record
for ($i = 0; $i < count($transactions); $i++){
echo "<tr><td>{$transactions[$i]['first_name']}</td><td> {$transactions[$i]['last_name']}
</td><td> {$transactions[$i]['product_title']} </td><td> {$transactions[$i]['product_description']} </td><td>
{$transactions[$i]['unit_price']} </td><td> {$transactions[$i]['quantity']} </td></tr>";
}
echo "</table>";
echo "</div>";
}
function getAll($sql, $values =null){
global $db;
$statm = $db->prepare($sql);
//Method 4
//assign a value to named parameters using an array
//$values= array(':genre'=>'drama');
$statm->execute($values);
//Fetch all records
$result = $statm->fetchAll();
return $result;
}
The sidemenu.php file calls each one from links:
<div id = 'sidebar'>
<h4>Links</h4>
<ul id = "nav" class= "text-left">
<li><a href='index.php'>Home</a></li>
<li><a href='index.php?action=products&product_type=tv'>TV Products</a></li>
<li><a href='index.php?action=products&product_type=cell'>Cell Phone Products</a></li>
<li><a href='index.php?action=products&product_type=computer'>Computer Products</a></li>
<li><a href='index.php?action=clients'>List of Customers</a></li>
<li><a href='index.php?action=transactions'>List of Transactions</a></li>
<!--<li><a href='index.php?action=moviesFS&genre=sci-fi&date_out=2009-12-15'>List of Favorite Sci-Fi Movies</a></li>-->
</ul>
</div>
As you can see, if I type my sql into my database it works just fine:

:namedand unnamed -?placeholders php.net/manual/en/pdo.prepare.php. Also, the OP is using PDO based on the methods->execute($values)and->fetchAll()