dto5637 2015-04-28 09:38
浏览 53

PHP:单击获取多个复选框的值,并为每个值单击获取值

I have a question regarding a php form. I've added a checkbox I would like it to select all in one click and click it separately.

<form name=myform action="addcanteen.php" method=post>
    <table><tr><td width="11%"> Date:</td><td width="89%"><input type="date" name="cdate" id="cdate"/></td></tr></table>
    <table border="1" bgcolor="#F5F9C1">
    <tr>
    <!--<th>ID</th>-->
    <th>Name</th>
    <td><!--<input type="text" id="datepicker">-->
      <input type="checkbox" id="selectall" name="chk[]"/></td>
    <td align="center">coffee</td>  
    <td align="center">tea</td>
    </tr>
    <?php while($row=mysql_fetch_array($result))
    {
    ?>
    <tr>
    <?php /*?><td><?php echo $row['emp_id'];?></td><?php */?>
    <td><?php echo $row['emp_name'];?></td>

    <td align="center"><input type="checkbox" class="name" name="chk1[]" value="<?php echo $row['emp_name'];?>"/></td>

    <td><input type="text" name="coffee[]" id="coffee" value="" /></td>
    <td><input type="text" name="tea[]" id="tea" value=""/></td>
    </tr>
    <?php } ?>
    <tr>
    <td>
    </td>
    <td>
    </td>
    <td align="center">
    <input type="submit" class="button" name="submit" id="submit" value="submit"/>
    </td>
    </tr>
    </table>
    </form>

here is the php code for the insertion, everything works there except the insertion of single checkbox selection.

<?php
    include(dbcon.php);
    date_default_timezone_set('UTC');
    /*$d=date("D");*/
    $date=date("d");
    $month=date("m");
    $year=date("Y");
    $fd=date("d-m-Y");
    if(isset($_POST['submit']))
    {
        $cdate=$_POST['cdate'];
    //$emp_id=$_POST['emp_id'];
    $checkbox1=$_POST['chk1'];
    $tea=$_POST['tea'];
    $coffee=$_POST['coffee'];
    /*$dd=date("d-m-y");*/
    for ($i=0; $i<sizeof($checkbox1);$i++) 
    {
    $query1="INSERT INTO canteen(name,coffee,tea,date)VALUES('".$checkbox1[$i]."','".$coffee[$i]."','".$tea[$i]."','$cdate')";
    $sql1=mysql_query($query1);
    }
    }
    header("location:canteen.php");
    ?>
  • 写回答

1条回答 默认 最新

  • douqing0713 2015-04-28 10:07
    关注

    I do get your point, But I suggest you to use map function in JavaScript with reference to class. For more info refer this link

    评论

报告相同问题?

悬赏问题

  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 来真人,不要ai!matlab有关常微分方程的问题求解决,
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算