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 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件