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

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日
  • 展开全部

悬赏问题

  • ¥15 请问读取环境变量文件失败是什么原因?
  • ¥15 在若依框架下实现人脸识别
  • ¥15 网络科学导论,网络控制
  • ¥100 安卓tv程序连接SQLSERVER2008问题
  • ¥15 利用Sentinel-2和Landsat8做一个水库的长时序NDVI的对比,为什么Snetinel-2计算的结果最小值特别小,而Lansat8就很平均
  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载