dtjzpg5313 2015-01-15 17:26
浏览 91
已采纳

too long

im create a survey system using php and mysql.. the problem here is i don't know how to pass the 'input name' when i click the submit button.

eg:

 1. Test 1
 <input type="text" name="name_{=$res[$a]['id']}">

 2. Test 2
 <input type="text" name="name_{=$res[$a]['id']}">

how to call the 'input name'?

 if(isset($_post['btnSubmit'])) {
    $xxx = $_post['name_????'];
    $yyy = $_post['name_????'];
 }

i replace the open/close php tag with {} because its not allowed..

edited

    <div class="form-body">
                    <h3 class="block"><?=$resSurvey[0]['survey_title']?></h3>
                    <p><?=$resSurvey[0]['survey_desc']?></p>
                    <br><br>

                    <?php
                        if ($rowQuestion >0) {
                            $bil=1;
                            for ($a=0; $a<$rowQuestion; $a++) {
                    ?>
                    <div class="form-group">
                        <label class="control-label col-md-3"><?=$bil?>. <?=$resQuestion[$a]['question_title']?></label>
                        <?php if ($resQuestion[$a]['question_type'] == 'tf') { ?>
                        <div class="radio-list col-md-4" >
                            <label class="radio-inline"><input type="radio" name="name_<?=$resQuestion[$a]['question_id']?>" value="t"> True </label>
                            <label class="radio-inline"><input type="radio" name="name_<?=$resQuestion[$a]['question_id']?>" value="f"> False </label>
                        </div>
                        <?php } ?>

                        <?php if ($resQuestion[$a]['question_type'] == 'st') { ?>
                        <div class="col-md-4">
                            <input type="text" name="name_<?=$resQuestion[$a]['question_id']?>" class="form-control" placeholder="Enter text">
                        </div>
                        <?php } ?>

                        <?php if ($resQuestion[$a]['question_type'] == 'lt') { ?>
                        <div class="col-md-4">
                            <textarea class="form-control" name="name_<?=$resQuestion[$a]['question_id']?>" rows="3"></textarea>
                        </div>
                        <?php } ?>

                        <?php 
                            if ($resQuestion[$a]['question_type'] == 'ms') {
                                $sqlOption = sprintf("select * from tbl_surveychoices where question_id=%d", mysql_real_escape_string($resQuestion[$a]['question_id']));
                                $resOption = selectSQL($sqlOption);
                                $rowOption = count($resOption);
                        ?>
                        <div class="radio-list col-md-4">
                            <?php for($b=0; $b<$rowOption; $b++) { ?>
                            <label class="radio"><input type="radio" name="name_<?=$resQuestion[$a]['question_id']?>" value="<?=$resOption[$b]['choices_id']?>"> <?=$resOption[$b]['choices_title']?></label>
                            <?php } ?>
                        </div>
                        <?php } ?>

                        <?php 
                            if ($resQuestion[$a]['question_type'] == 'mm') {
                                $sqlOption = sprintf("select * from tbl_surveychoices where question_id=%d", mysql_real_escape_string($resQuestion[$a]['question_id']));
                                $resOption = selectSQL($sqlOption);
                                $rowOption = count($resOption);
                        ?>
                        <div class="radio-list col-md-4">
                            <?php for($b=0; $b<$rowOption; $b++) { ?>
                            <label><input type="checkbox" name="name_<?=$resQuestion[$a]['question_id']?>[]" value="<?=$resOption[$b]['choices_id']?>">  <?=$resOption[$b]['choices_title']?> </label>
                            <?php } ?>
                        </div>
                        <?php } ?>
                    </div>
                    <?php
                                $bil++;
                            }
                        }
                    ?>
                </div>
  • 写回答

2条回答 默认 最新

  • dshkmamau65777662 2015-01-15 17:57
    关注

    I would make it easier on yourself and make the input names have an index of ??? instead

     name="name_<?=$resQuestion[$a]['question_id']?>[]"
    

    becomes

    name="name['<?=$resQuestion[$a]['question_id']?>'][]"
    

    Then on submit becomes

    if(isset($_post['btnSubmit'])) {
       foreach ($_POST['name'] as $question_id => $values) {
          $xxx[$question_id] =  $values;
       }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?