来自 mysql 的表单输入名称
form input name from mysql
我正在使用 php 和 mysql 创建一个调查系统。这里的问题是我不知道如何在单击提交按钮时通过 'input name'。
例如:
1. Test 1
<input type="text" name="name_{=$res[$a]['id']}">
2. Test 2
<input type="text" name="name_{=$res[$a]['id']}">
如何调用'input name'?
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>
$inside = 'name_'.$res[$a]['id'];
$xxx = $_POST[$inside];
试试这个
我会让你自己更轻松,让输入名称的索引为 ???相反
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;
}
}
我正在使用 php 和 mysql 创建一个调查系统。这里的问题是我不知道如何在单击提交按钮时通过 'input name'。
例如:
1. Test 1
<input type="text" name="name_{=$res[$a]['id']}">
2. Test 2
<input type="text" name="name_{=$res[$a]['id']}">
如何调用'input name'?
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>
$inside = 'name_'.$res[$a]['id'];
$xxx = $_POST[$inside];
试试这个
我会让你自己更轻松,让输入名称的索引为 ???相反
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;
}
}