从mysql表单输入名称

时间:2015-01-15 17:26:43

标签: php mysql forms input

我使用php和mysql创建一个调查系统..这里的问题是当我点击提交按钮时,我不知道如何传递'输入名称'。

例如:

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

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

如何调用'输入名称'?

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

我用{}替换open / close php标签,因为它不允许..

编辑

    <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 个答案:

答案 0 :(得分:0)

$inside = 'name_'.$res[$a]['id'];    
$xxx = $_POST[$inside];

试试这个

答案 1 :(得分:0)

我会让自己更容易,并使输入名称的索引为???代替

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

变为

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

然后提交成为

if(isset($_post['btnSubmit'])) {
   foreach ($_POST['name'] as $question_id => $values) {
      $xxx[$question_id] =  $values;
   }
}