1

我正在尝试使用提供两个 php 脚本的控制器脚本创建一个简单的购物车,但我似乎遇到了一些问题。下面是我的三个脚本的代码,后面是我当前收到的错误消息。

    <?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
4

1 回答 1

1

您没有名为 htmlout 的函数,因此它没有引用任何内容(因此出现错误)。

您需要创建一个 htmlout 函数

就像是

public function htmlout($params){
    /*Processes to make the html*/
    $value = $item[$params];
    return $value
}

*编辑功能布局,我最近一直在使用太多不同的语言..

于 2013-11-14T20:42:01.620 回答