duanli6834 2013-04-24 13:10
浏览 50
已采纳

重复表单 - 添加到数据库

Ok so the form starts with a drop down which asks the question 'Select how many children you have' and you can select 1-10 and this generates duplicate forms (exact same fields) for the appropriate amount. What I want to know is how can I add each duplicate form to one table.

For example, what I want is: someone has 5 children, each child would get a row in the children table.

At the moment, if 1 child is selected and details are entered, they get entered in the table just fine. So why is it stopping that when its done for more than one, and how can I fix it?

I can update the question to post code if anyone wishes to see it, however the code is just a small part of the whole page (using JavaScript, PHP, HTML and MySQL) and things will get confusing. I'm just looking for ideas and pointers.

  • 写回答

3条回答 默认 最新

  • dqrzot2791 2013-04-24 13:14
    关注

    Use a counter for the form and add a number to the fieldname

    <form>
    <?php $counter = 1; ?>
    <input type="text" name="child[<?php echo $counter; ?>][name]">
    <input type="text" name="child[<?php echo $counter; ?>][age]">
    ... rest of the form ...
    <?php $counter++; ?>
    </form>
    

    use $_POST array to retrieve the data in the script that updates the database

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧