加了,但还是一样
而且如果$_SESSION["cart"] = new CART; 
用一个变量比如$_SESSION["cart"] = 1;
运行的很好,一点错误也没有

解决方案 »

  1.   

    <?php
    include "2.php";
    session_start(); // 启用session// 根据控制信息操作购物车
    if($_POST['cmd1']) {
      $cart->insert();
    }else{
    if($_POST['cmd2']) {
      $cart->delete();
    }
    }
    ?>
    <form method="post">
    <input type=text value=<?php echo $cart->data; ?>>
    <input type=submit name="cmd1" value="+">
    <input type=submit name="cmd2" value="-">
    </form><?php
    class CART {
      var $data = 0;
      function insert() {
        $this->data++;
      }
      function delete() {
        $this->data--;
        if($this->data < 0)
          $this->data = 0;
      }
    }if(! isset($_SESSION["cart"]))
      $_SESSION["cart"] = new CART; // 若购物车没有创建则创建
    $cart =& $_SESSION["cart"]; // 取回保存在session中的购物车
    ?>
      

  2.   

    你把include "2.php";改成require_once "cart.php";我忘了改了
      

  3.   

    还是那个错误,点一下按钮就出来了
    session里面应该可以放类吧
      

  4.   

    我也不晓得哪里出错了,搞得我好烦
    你的php.ini怎么配的啊?