【发布时间】:2015-11-25 16:06:06
【问题描述】:
嗨,我的表单中有很多输入,其中一些是单选按钮,另一些是文本和文本框。我通过
获得所有这些值foreach ($_POST as $name => $val)
{
//for example if post type==radio
//there is some insertion codes to db in here $name,$val...
}
但如果 post 值是单选按钮,我想使用该插入。我该怎么做?
我的表单看起来像
<form method="post" action="<?=$_SERVER['REQUEST_URI']?>">
.
.
.
//a lot of table,tr,td,input,etc. in this part
.
.
.
<td style="border-style:solid; border-width:2px 1px 1px 2px"><input type="radio" class="metalYayaKorkuluk_Deformasyon" name="metalYayaKorkuluk_Deformasyon" style="width:100%; margin:0px; display:table-caption" value="1" /></td>
<td style="border-style:solid; border-width:2px 1px 1px 1px"><input type="radio" class="metalYayaKorkuluk_Deformasyon" name="metalYayaKorkuluk_Deformasyon" style="width:100%; margin:0px; display:table-caption" value="2" /></td>
<td style="border-style:solid; border-width:2px 1px 1px 1px"><input type="radio" class="metalYayaKorkuluk_Deformasyon" name="metalYayaKorkuluk_Deformasyon" style="width:100%; margin:0px; display:table-caption" value="3" /></td>
<td style="border-style:solid; border-width:2px 2px 1px 1px"><input type="radio" class="metalYayaKorkuluk_Deformasyon" name="metalYayaKorkuluk_Deformasyon" style="width:100%; margin:0px; display:table-caption" value="4" /></td>
<td style="border-style:solid; border-width:1px 1px 2px 2px"><input type="radio" class="plastikKaplama4" name="plastikKaplama4" style="width:100%; margin:0px; display:table-caption" value="1" <?php echo ($plastikKaplama4=='1')?'checked':'' ?>/></td>
<td style="border-style:solid; border-width:1px 1px 2px 1px"><input type="radio" class="plastikKaplama4" name="plastikKaplama4" style="width:100%; margin:0px; display:table-caption" value="2" <?php echo ($plastikKaplama4=='2')?'checked':'' ?>/></td>
<td style="border-style:solid; border-width:1px 1px 2px 1px"><input type="radio" class="plastikKaplama4" name="plastikKaplama4" style="width:100%; margin:0px; display:table-caption" value="3" <?php echo ($plastikKaplama4=='3')?'checked':'' ?>/></td>
<td style="border-style:solid; border-width:1px 2px 2px 1px"><input type="radio" class="plastikKaplama4" name="plastikKaplama4" style="width:100%; margin:0px; display:table-caption" value="4" <?php echo ($plastikKaplama4=='4')?'checked':'' ?>/></td>
<input id='elm2' type="submit" name="save2" value="Submit" />
</form>
总结一下,我试图使用 foreach 获取所选单选按钮的所有名称及其值,但我不想获取其他输入,例如 text 和 textarea。
【问题讨论】:
-
这里有一些语法错误。请参阅以下链接 php.net/manual/en/mysqli.error.php 和 php.net/manual/en/function.error-reporting.php 并将其应用于您的代码。
-
$_POST 数组不包含有关值来自什么输入类型的任何信息。您需要根据名称进行过滤。或者将您的选择输入类型命名为独特的名称,例如 name="select_foo"
-
即使您进行了编辑,它仍然包含语法错误。使用我给你的链接来解决/调试你的代码。我们也不知道您的 $_POST 是什么样的。
-
好的,那么您使用的表格在哪里?