dongxieyi9115 2015-02-21 16:41
浏览 7

too long

I have three check box and three input field something like this,

        <input type="checkbox" name="fruit" value="orange" >
        <input type="text" name="orange" >Orange
        <input type="checkbox" name="fruit" value="apple" >
        <input type="text" name="n" >Apple<br/>
        <input type="checkbox" name="fruit" value="mango" >
        <input type="text" name="mango" >Mango

I have a mysql table named fruits with four column named id, apple, orange, mango. I want to do something like if user select orange , apple , mango (checkboxes) I want to insert data into orange , apple , mango in the table from the three input field , or if user select two user check box it will just insert data into two columns from the input field's value, or if just one check box is selected then insert into one column! what is the standard procedure to do that? Thanks in advance

  • 写回答

2条回答 默认 最新

  • dongyou26216708 2015-02-21 16:50
    关注

    Only checked checkboxes are sent, so use isset:

    if (isset($_POST['mango']) || isset($_POST['apple']) || isset($_POST['orange'])) {
        $query = 'INSERT INTO table VALUES (orange, apple, mango) VALUES (';
        $query .= (isset($_POST['orange']) ? 1 : '') . ',';
        $query .= (isset($_POST['apple'])  ? 1 : '') . ',';
        $query .= (isset($_POST['mango'])  ? 1 : ''); 
        $query .= ')';
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看