dp709369831 2013-07-14 17:08
浏览 47
已采纳

通过同时检查多个类别

I would like to get more checkbox content into my database. It means that I have categories of php, java, html and css but I click on php and html, so it must be the two into in the same database that is within the database category.

It looks like this when I lie in the database:

$kategori = $_POST["kategori"];

How it looks when the user must select a category such as php and html to the database:

<input type="checkbox" name="kategori[]" value="<?php echo $tekst;?>"/>
<?php echo $tekst;?>

Right now when I put it into the database writes just "array" and nothing else even though I have selected two categories to the database.

How do I put multiple categories into the database same time?

  • 写回答

2条回答 默认 最新

  • duandongjin5647 2013-07-14 17:21
    关注

    say for example you have 2 checkbox:

    <input type="checkbox" name="kategori[]" value="1"/>
    <input type="checkbox" name="kategori[]" value="2"/>
    

    so when you submit the form in the submit page the data in the variable is $_POST["kategori"] is structure as:

    Array([0] => 1
          [1] => 2
          ); //which you could see by executing the code print_r($_POST["kategori"]);
    

    So in order to put it into the database you can change it into a comma seperated string and insert under a single field in the database table

    $kategori = implode(",",$_POST["kategori"]); //which will give the output "1,2" when you do echo $kategori;
    

    I hope this can be of some help

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥50 求解vmware的网络模式问题
  • ¥24 EFS加密后,在同一台电脑解密出错,证书界面找不到对应指纹的证书,未备份证书,求在原电脑解密的方法,可行即采纳
  • ¥15 springboot 3.0 实现Security 6.x版本集成
  • ¥15 PHP-8.1 镜像无法用dockerfile里的CMD命令启动 只能进入容器启动,如何解决?(操作系统-ubuntu)
  • ¥30 请帮我解决一下下面六个代码
  • ¥15 关于资源监视工具的e-care有知道的嘛
  • ¥35 MIMO天线稀疏阵列排布问题
  • ¥60 用visual studio编写程序,利用间接平差求解水准网
  • ¥15 Llama如何调用shell或者Python
  • ¥20 谁能帮我挨个解读这个php语言编的代码什么意思?