dongwu9063 2012-07-06 03:04
浏览 67

如何使用复选框对应的值将多个数据插入mysql?

i have been trying to insert multiple values to mysql using checkbox. my code goes like this.

    <form name='form' method='post'>
    <table>
    <?php
    $id=$_REQUEST['ID'];
    $sql=mysql_query("SELECT * FROM table WHERE id='".$id."'");
    while($row=mysql_fetch_array($sql)){
    ?>
    <tr>
    <td><input type="checkbox" name="select[]" value="<?php echo "$id"; ?>"/></td>
    <td><?php echo $row['shapes']; ?></td>
    <td><?php echo $row['area']; ?></td>
    <td><?php echo $row['characteristic']; ?></td>
    </tr>
    </form>
    <?php
    }//end whil loop
    ?>
    <tr>
    <td><input type="submit" name="submit" value="submit" class="del"/>      
    </td>
    </tr>
    </table>

    <?php
    if(isset($_POST['submit'])){
    $select[] = $_POST['select'];
    $select=$_POST['select'];

    for($i=0;$i<sizeof($select);$i++){
       $query=mysql_query("INSERT INTO table2(id, shapes, area, characteristic)
       VALUES('".$select[$i]."', '".$row['shapes']."', 
            '".$row['area']."', '".$row['characteristic']."')");
    }//end for loop
   }
   ?>

i was able to correctly insert the checkbox value to table2 but the problem is, those values that go to shapes, area, characteristic fields are not the corresponding values. The values that are being inserted are the values of the last data from table. please help. only the checkbox value are being inserted correctly.

  • 写回答

1条回答 默认 最新

  • duanfen2008 2012-07-06 06:20
    关注

    Oh, I get it. I have to add a hidden button for the other fields. Thanks.

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100