<form id="formcar" name="formcar" method="post" action="car.php">
                <input type='hidden' name='id[]' value='22' />
                <input type='hidden' name='id[]' value='23' />
                <input type='hidden' name='id[]' value='24' />
                <input type='hidden' name='id[]' value='25' />
                <button type="submit" name="button" class="btn-2">购买</button>
                </form>
    $buynum = isset($buynum) && is_numeric($buynum) ? $buynum : 1;
    $id =empty($id)? "" : intval($id);
    $buynum = ($buynum < 1) ? 1 : $buynum;
    $rs = $dsql->GetOne("SELECT id,channel,title FROM #@__archives WHERE id='$id'");
    if(!is_array($rs))
    {
        ShowMsg("该商品已不存在!","-1");
        exit();
    }
    $cts = GetChannelTable($rs['channel']);
    $rows = $dsql->GetOne("SELECT aid as id,trueprice as price,units FROM `$cts[addtable]` WHERE aid='$id'");
    if(!is_array($rows))
    {
        ShowMsg("该商品已不存在!","-1");
        exit();
    }
    $rows['buynum'] = $buynum;
    $rows['title']     = $rs['title'];
    $cart->addItem($id, $rows);
    ShowMsg("已添加加到购物车,<a href='car.php'>查看购物车</a>","car.php");
    exit();我需要如何修改才能将id提交的内容到php?

解决方案 »

  1.   

    这就是全部代码? print_r($_POST['id']);  //即为提交的id值
      

  2.   


    <?php
    /**
     *
     * 发送到购物车
     *
     * @version        $Id: posttocar.php 1 15:38 2010年7月8日Z tianya $
     * @package        DedeCMS.Site
     * @copyright      Copyright (c) 2007 - 2010, DesDev, Inc.
     * @license        http://help.dedecms.com/usersguide/license.html
     * @link           http://www.dedecms.com
     */
    require_once (dirname(__FILE__) . "/../include/common.inc.php");
    require_once DEDEINC.'/shopcar.class.php';
    $cart = new MemberShops();$do = isset($do) ? trim($do) : 'add';if($do == 'add')
    {
        /*
        function addItem();                add a product to car
        */
        $buynum = isset($buynum) && is_numeric($buynum) ? $buynum : 1;
        $id =empty($id)? "" : intval($id);
        $buynum = ($buynum < 1) ? 1 : $buynum;
        $rs = $dsql->GetOne("SELECT id,channel,title FROM #@__archives WHERE id='$id'");
        if(!is_array($rs))
        {
            ShowMsg("该商品已不存在!","-1");
            exit();
        }
        $cts = GetChannelTable($rs['channel']);
        $rows = $dsql->GetOne("SELECT aid as id,trueprice as price,units FROM `$cts[addtable]` WHERE aid='$id'");
        if(!is_array($rows))
        {
            ShowMsg("该商品已不存在!","-1");
            exit();
        }
        $rows['buynum'] = $buynum;
        $rows['title']     = $rs['title'];
        $cart->addItem($id, $rows);
        ShowMsg("已添加加到购物车,<a href='car.php'>查看购物车</a>","car.php");
        exit();
    }
    elseif($do == 'del')
    {
        /*
        function delItem();                del products from car
        */
        if(!isset($ids))
        {
            ShowMsg("请选择要删除的商品!","-1");
            exit;
        }
        if(is_array($ids))
        {
            foreach($ids as $id)
            {
                $id = intval($id);
                $cart->delItem($id);
            }
        }
        else
        {
            $ids = intval($ids);
            $cart->delItem($ids);
        }
        ShowMsg("已成功删除购物车中的商品,<a href='car.php'>查看购物车</a>","car.php");
        exit;
    }
    elseif($do == 'clear')
    {
        /*
        function clearItem();        clear car products all!
        */
        $cart->clearItem();
        ShowMsg("购物车中商品已全部清空!","car.php");
        exit;
    }
    elseif($do == 'update')
    {
        /*
        function updateItem();        update car products number!
        */
        if(isset($ids) && is_array($ids))
        {
            foreach($ids as $id){
                $id = intval($id);
                $rs = $dsql->GetOne("SELECT id,channel,title FROM #@__archives WHERE id='$id'");
                if(!is_array($rs)) continue;
                $cts = GetChannelTable($rs['channel']);
                $rows = $dsql->GetOne("SELECT aid as id,trueprice as price,units FROM `$cts[addtable]` WHERE aid='$id'");
                if(!is_array($rows)) continue;
                $rows['buynum'] = intval(${'buynum'.$id});
                if($rows['buynum'] < 1)
                {
                    //如果设单位数量小于1个时更新,则移出购物车
                    $cart->delItem($id);
                    continue;
                }
                $rows['title']     = $rs['title'];
                $cart->addItem($id, $rows);
            }
        }
        ShowMsg("购物车中商品已全部更新!","car.php");
        exit;
    }
    全部的php代码
      

  3.   

    这么说吧,就是提交表单内的数据,比如,数据表A中有一个字段名称为id,html页想批量提交即:<input type='hidden' name='id[]' value='22' />,这个可以有N条,如何把id的内容提交给php,就这个意思。
      

  4.   

    等于是一个表单的内容给php处理
      

  5.   

    直接点击“购买”就能提交form数据,当然action必须指向你的php接收页面。<?php
    if(isset($_POST['id'])){
    print_r($_POST['id']);
    #Array ( [0] => 22 [1] => 23 [2] => 24 [3] => 25 )
    }
    ?>
    <form id="formcar" name="formcar" method="post" action="test18.php">
        <input type='hidden' name='id[]' value='22' />
        <input type='hidden' name='id[]' value='23' />
        <input type='hidden' name='id[]' value='24' />
        <input type='hidden' name='id[]' value='25' />
        <button type="submit" name="button" class="btn-2">购买</button>
    </form>
      

  6.   

    $_POST['id']是一个array,楼主问的到底是什么。
      

  7.   


    以上代码中其实就是一个购物提交跟一个购物车的页面,我是想问,能通过什么方法可以批量提交商品到购物车。
    页面代码:
                    <form id="formcar" name="formcar" method="post" action="car.php">
                    <input type='hidden' name='id[]' value='名称1' />
                    <input type='hidden' name='id[]' value='名称2' />
                    <input type='hidden' name='id[]' value='名称3' />
                    <input type='hidden' name='id[]' value='名称4' />
                    <button type="submit" name="button" class="btn-2">购买</button,>
                    </form>
    代码也可以按照上面的来理解,分别把《名称1》做为一条数据添加到购物车(即php页面),往下的《名称2》以此类推。这样是否明了些呢?
      

  8.   


    几乎所有的楼层都是在解答你, 你却没听懂.$_POST['id']是一个array,楼主问的到底是什么。遍历$_POST['id'], 逐条mysql insert,懂了吗。
      

  9.   

    那得看你的form中是怎么写的,如果在input中的value有值,那么post提交时就会接收到。value为空,则不会被获取值