コントローラー スクリプトを使用して 2 つの php スクリプトを供給する単純なショッピング カートを作成しようとしていますが、いくつかの問題が発生しているようです。以下は、私の 3 つのスクリプトのコードと、現在受け取っているエラー メッセージです。
<?php
$items = array(
array('radio_id' => '1', 'manufacturer' => 'Grundig', 'model' => 'G3', 'price' => 129.99),
array('radio_id' => '2', 'manufacturer' => 'Eton', 'model' => 'E5', 'price' => 99.99),
array('radio_id' => '3', 'manufacturer' => 'Eton', 'model' => 'E1', 'price' => 399.99),
array('radio_id' => '4', 'manufacturer' => 'Morphy Richards', 'model' => 'DRM Radio', 'price' => 199.99),
array('radio_id' => '5', 'manufacturer' => 'Sony', 'model' => 'ICF-SW7600GR', 'price' => 149.99),
array('radio_id' => '6', 'manufacturer' => 'TechniSat', 'model' => 'MultyRadio', 'price' => 149.99));
session_start();
if (!isset($_SESSION['cart']))
{
$_SESSION['cart'] = array();
}
print_r($_SESSION);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<?php
//linking my database to the script.
$link = mysqli_connect('bt2201-1213.bimserver2.com', 'db', 'dbpw', 'db');
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Products</title>
</head>
<body>
<?php
if (!isset($_SESSION['cart']))
{
$_SESSION['cart'] = array();
}
if (isset($_POST['action']) and $_POST['action'] == 'Buy')
{
$_SESSION['cart'][] = $_POST['radio_id'];
header('Location:.');
exit();
}
if (isset($_POST['action']) and $_POST['action'] == 'Empty cart')
{
unset($_SESSION['cart']);
header('Location: ?cart');
exit();
}
if (isset($_GET['cart']))
{
$cart = array();
$total = 0;
foreach($_SESSION['cart'] as $id)
{
foreach ($items as $product)
{
if ($product['radio_id'] == $id)
{
$cart[] = $product;
$total += $product['price'];
break;
}
}
}
include 'shopping_basket.html.php';
exit();
}
include 'all_radios_2.html.php';
?>
</body>
</html>
<body>
<h1> Your Shopping Basket</h1>
<?php if (count($cart) > 0); ?>
<table>
<thead>
<tr>
<th>Manufacturer</th>
<th>Model</th>
<th>Pirce</th>
</tr>
</thead>
<tfoot>
<tr>
<td>Total:</td>
<td>$<?php echo number_format ($total, 2); ?></td>
</tr>
</tfoot>
<tbody>
<?php foreach ($cart as $item); ?>
<tr>
<td><?php htmlout($item['manufacturer']); ?></td>
<td><?php htmlout($item['model']); ?></td>
<td>$<?php echo number_format($item['price'], 2); ?></td>
</tr>
</tbody>
</table>
<?php else; ?>
<p>Your shopping basket is empty!</p>
<?php endif; ?>
<form action="" method="post">
<p>
<a href="">Continue Shopping</a> or
<input type="submit" name="action" value="Empty Basket"/>
</p>
</form>
</body>
<body>
<p> Your shopping cart currently contains <?php echo count($_SESSION['cart']); ?>items.<p>
<p><a href="">View your cart.</a></p>
<table border="1">
<thead>
<tr>
<th>Manufacturer</th>
<th>Model</th>
<th>Pirce</th>
</tr>
</thead>
<tbody>
<?php foreach ($items as $item);?>
<tr>
<td><?php htmlout($item['manufacturer']); ?></td>
<td><?php htmlout($item['model']); ?></td>
<td><?php echo number_format($item['price'], 2);?></td>
<td>
<form action="" method="post">
<div>
<input type="hidden" name="id" value="<?php htmlout($item['radio_id']); ?>"/>
<input type="subbit" name"action" value="Buy"/>
</div>
</form>
</td>
</tr>
</tbody>
</table>
</body>
Error is Fatal error: Call to undefined function htmlout() in /home/ncooney2/ncooney2.bimserver2.com/all_radios_2.html.php on line 23