简体   繁体   English

将复选框插入mysql数据库

[英]Insert checkboxes into mysql database

Would like some help on how to store values from dynamic checkboxes into a mySQL table using php. 想要有关如何使用php将动态复选框中的值存储到mySQL表中的帮助。

                    ID |        DES_ID  | CAT_ID
                    1           0921671     12
                    2           0921671     24
                    3           0921671     30

I generate my checkboxes like this. 我生成这样的复选框。

<?php 
                $result = mysql_query("SELECT * FROM tbl_category order by name ");
                $i=1;
                while($row = mysql_fetch_array($result)){
                echo '<input type="checkbox" name="categories[]" value='.$row['category_id'].' id='.$row['name'].'>'.'<label for='.$row['name'].' class="fil_lab">'.$row['name']. '</label>';
                if($i%5==0)
                {
                 $i = 0;
                 echo '<br><br>';
                }
                $i++;}
            ?>

Note: I will add those checkboxes as other data like, Destination Name etc. . 注意:我会将这些复选框添加为其他数据,例如“目的地名称”等。 I have a total of 4 tables to be inserted at the same time. 我总共有4张桌子要同时插入。

You can add a separate table for check boxes, which you can link with a foreign key to main table. 您可以为复选框添加单独的表,并可以使用外键将其链接到主表。

OR 要么

You can create a field in main table and store check box values like this (0|1|2) but this is not a good method, follow the first one. 您可以在主表中创建一个字段,并像这样(0 | 1 | 2)存储复选框值,但这不是一个好方法,请遵循第一个方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM