小黑帽子 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日
  • 展开全部

悬赏问题

  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)
  • ¥15 AIC3204的示例代码有吗,想用AIC3204测量血氧,找不到相关的代码。