小黑帽子 2022-10-27 18:20 采纳率: 50%
浏览 40
已结题

PHP checkbox多选怎么入数据库和显示出来

PHP checkbox多选怎么入数据库和显示出来

 <form action="aa_ajax.php?action=survey" method="post" enctype="multipart/form-data" onsubmit="return check_inquiry();">
          <input type="hidden" name="id" value="<?php echo $id; ?>" />
          <div style="width:80%; margin:0 auto;">
           <p>
           你是怎么知道我们的?
          </p>
           <p>
           <label style="width:auto;margin-right:15px;"><input type="checkbox" name="knowgla[]" value="1">  销售联系</label>
           <label style="width:auto;margin-right:15px;"><input type="checkbox" name="knowgla[]" value="2">  搜索引擎搜索</label>
           <label style="width:auto;margin-right:15px;"><input type="checkbox" name="knowgla[]" value="3">  多媒体视频</label>
           <label style="width:auto;margin-right:15px;"><input type="checkbox" name="knowgla[]" value="4">  微博</label>
           <label style="width:auto;margin-right:15px;"><input type="checkbox" name="knowgla[]" value="5">  邮箱</label>
           <label style="width:auto;margin-right:15px;"><input type="checkbox" name="knowgla[]" value="6">  微信群</label>
           <label style="width:auto;margin-right:15px;"><input type="checkbox" name="knowgla[]" value="7">  其他</label>
          </p>
          <p>&nbsp;</p>
           <p>
            希望得到我们哪些支持
          </p>
           <p>
           <label style="width:auto;margin-right:15px;"><input type="checkbox" name="interests[]" value="1">  支持A</label>
           <label style="width:auto;margin-right:15px;"><input type="checkbox" name="interests[]" value="2">  支持B</label>
           <label style="width:auto;margin-right:15px;"><input type="checkbox" name="interests[]" value="3">  支持C</label>
          </p>
          <p>&nbsp;</p>
          
          
          
         
         
        
         <p>对我们满意度打分 </p>
           <p>
           <label style="width:auto;margin-right:15px;"> <input name="satisfaction1" type="radio" value="1" <?php if ($rsText[satisfaction1]==1){ ?>checked <?php } ?> />  1</label>
           <label style="width:auto;margin-right:15px;"> <input name="satisfaction1" type="radio" value="2" <?php if ($rsText[satisfaction1]==2){ ?>checked <?php } ?>  />  2</label>
           <label style="width:auto;margin-right:15px;"> <input name="satisfaction1" type="radio" value="3" <?php if ($rsText[satisfaction1]==3){ ?>checked <?php } ?>  />  3</label>
           <label style="width:auto;margin-right:15px;"> <input name="satisfaction1" type="radio" value="4" <?php if ($rsText[satisfaction1]==4){ ?>checked <?php } ?>  />  4</label>
           <label style="width:auto;margin-right:15px;"> <input name="satisfaction1" type="radio" value="5" <?php if ($rsText[satisfaction1]==5){ ?>checked <?php } ?>  />  5</label>
          </p>
          <p>&nbsp;</p>
         
        
         
          <div class="clear"></div>

              
              
            <p class="submit"><input type="submit"  value="Submit"  class="sub_anniu" /></p>
           </div>
                
        </form> 
if($action == "survey")
{
    $id = check_sql($_POST[id]);
    $page = check_sql($_POST[page]);
    if($_POST)
    {
        $data = $_POST;        
        
        if(empty($_POST[id])){ ShowMessages('page.php?page='.$data[page].'&id='.$data[id],'有内容为空');}else{
        $where[id] = $_POST[id];        
        $tb = "tb_survey";
        $datano = array("id","page");
        $sql = ChangeSql($data,$where,$tb,$datano);
        if($sql[MessageID]==1){
            ShowMessages('page.php?page='.$data[page].'&id='.$data[id],'Successful');
         }else
           {
               ShowMessages('page.php?page='.$data[page].'&id='.$data[id],'含有非法字符6');
        }
        }
    }
}

怎么把knowgla 和 interests多选结果放到数据库knowgla 和 interests字段里,并在页面上选中了就保持为选中的状态;请帮我写出来,谢谢

  • 写回答

1条回答 默认 最新

  • 一把编程的菜刀 2022-10-27 18:59
    关注

    至少有2中方式存储把,第一种是$data ['knowgla']=implode(',',$_POST['knowgla']) 这样转换成字符保持到数据库,然后读取的以后再用explode(',',$row['knowgla'])转成数组,再使用in_array判断是否在数组中而判断是否选中

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 系统已结题 11月5日
  • 已采纳回答 10月28日
  • 赞助了问题酬金15元 10月27日
  • 修改了问题 10月27日
  • 展开全部

悬赏问题

  • ¥170 如图所示配置eNSP
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装