如何在不同的会话中绑定多个复选框

时间:2017-12-08 06:04:27

标签: javascript php jquery ajax

我有一些带复选框的数据。现在我想,当任何一个单击复选框时,所有已检查的数据应该在会话中绑定,并应在下一页上进行。再次,如果任何人点击复选框,那么新的点击数据应该在会话中。但是旧数据不应该删除。我试过但没有工作,任何事情。请帮忙。

                            

                            <form  name="reservation_form" class="reservation-form mb-0" action="second.php" method="post" novalidate>

            <div class="col-xs-12 col-sm-6 col-md-4">
            <div class="form-group mb-15">
              <input name="name1" class="form-control required " type="text" placeholder="Enter Name" aria-required="true">
            </div>
          </div>
          <div class="col-xs-12 col-sm-6 col-md-4">
            <div class="form-group mb-15">
              <input name="email1" class="form-control required " type="email" placeholder="Enter Email" aria-required="true">
            </div>
          </div>
          <div class="col-xs-12 col-sm-6 col-md-4">
            <div class="form-group mb-15">
              <input name="phone1" class="form-control required " type="text" placeholder="Enter Phone" aria-required="true">
            </div>
          </div>
     <?php
            $query1=mysql_query("select * from lab_location_package_rel where city_id='$selectcity1' AND area_id='$selectarea1' AND lab_id='$selectlab1'") or die (mysql_error());          
             while($value = mysql_fetch_array($query1)) {
                 $mrp=$value['mrp'];
                 $opp=$value['offer_price_perc'];
                 $package_id=$value['package_id'];

                 $per=$mrp*$opp/100;
                 $total=$mrp-$per;

             $query2=mysql_query("select * from package_master where id='$package_id'") or die (mysql_error());
             $value2 = mysql_fetch_array($query2);
             ?>     
                    <li class="list-group-item">
                        <div class="checkbox">
                            <input type="checkbox" id="checkbox" name="name[]" />
                            <label for="checkbox">
                               <b>Package Name:</b> <?php echo $value2['package_title']; ?> <br>
                               <b>MRP:</b>  <strike><?php echo $value['mrp']; ?>  </strike><br>
                               <b>Offer Price:</b>  <?php echo $total; ?>
                            </label>
                        </div>
                        <div class="pull-right action-buttons">
                            <a href="#" class="btn btn-info">View Details</a>
                       </div>
                    </li>
              <?php } ?>     

                </ul>
            </div>
       <input type="button" class="pull-right btn btn-warning" value="Submit">
    </form>

在给定代码中,当任何一个填写所有字段并单击复选框时 -

<input type="checkbox" id="checkbox" name="name[]" />
                        <label for="checkbox">
                           <b>Package Name:</b> <?php echo $value2['package_title']; ?> <br>
                           <b>MRP:</b>  <strike><?php echo $value['mrp']; ?>  </strike><br>
                           <b>Offer Price:</b>  <?php echo $total; ?>
                        </label>

然后所有填写的字段和包名称,MRP,报价(将为每个复选框选择这些名称)应该在会话中绑定。

1 个答案:

答案 0 :(得分:1)

通过这样的方式并在提交表单时通过

获取值

输入类型=&#34;复选框&#34; ID =&#34;复选框&#34;命名=&#34;名称[]&#34;值=&#34; $ 2 [&#39; PACKAGE_TITLE&#39;]&#34;&GT;

输入类型=&#34;复选框&#34; ID =&#34;复选框&#34;命名=&#34;名称[]&#34;值=&#34; $值[&#39; MRP&#39;]&#34;&GT;

输入类型=&#34;复选框&#34; ID =&#34;复选框&#34;命名=&#34;名称[]&#34;值=&#34; $总&#34; /&GT;

$名称= $ _ POST [&#39;名称&#39;]; $ answer = implode($ name,&#34;,&#34;);

然后将名称值分配给会话。

$ _ SEESION [&#39;名称&#39;] = $答案;