首页 > 解决方案 > 如何在 PHP 中选择数据库 mysqli 表中的复选框

问题描述

**如何在数据库 mysqli 中选择复选框我应该在复选框值中写什么请帮助我还将数组转换为字符串的内爆函数没有找到要打印的复选框值的值。.....还要检查图片上的输出... **

输出图片

        <?php
        while($fetch=mysqli_fetch_array($select))
        {
         ?>

        <tr>
        <td><?php echo $fetch["tableno"]?></td>
        <td><?php echo $fetch["customerid"]?></td>
        <td><?php echo $fetch["item"]?></td>
        <td><?php echo $fetch["money"]?></td>
        <td><a href="javascript:del_tableno(<?php echo $fetch["tableno"];?>)"><button>Delete</button></a></td>
        <td><a href="update.php?tableno=<?php echo $fetch["tableno"]; ?>"/><button>Update</button></td>

        <td><form method="POST">
            <input type="checkbox" name="chk[]" value="???">
            <input type="submit" name="sub1" value="Button for Checkbox">

            </td> </form>
        </tr>

        <?php

        }?>


    </table>

        <p style="font-size:30px">The Customer has TO Selected these Items from Menu List
    and therefore submitted to<br> Kitchener to Make the Food and
    then waiter will serve the Food to Customer.</p>
        </body>

    </html>
    <?php
     if(isset($_POST['sub1']))
      {
      $chk=implode(',', $_POST['chk']);
       echo "<br>Customer has  selected the following checkbox Item to be Prepared and Eat the Food:<br/>";

        echo "<br/>".$chk."<br><br/><br/><br/><br/>";

          }  

          ?>

标签: phpmysqli

解决方案


试试这个:

在您的表单中,插入多个复选框的方法

<form method="POST" action="test2.php">
        <input type="checkbox" name="chk[]" value="InputText1">InputText1<br>
        <input type="checkbox" name="chk[]" value="InputText2">InputText2<br>
        <input type="submit" name="sub1">
</form>


if(isset($_POST['sub1'])) // check the submitted form and print the values
   {
     echo "You selected the following checkbox:<br/>";
     foreach ($_POST['chk'] as $value) {
      echo $value."<br>";
    }

推荐阅读