Php 无法选择单选按钮
我的问题是我不能选择单选按钮。我正在使用php mysql,并在while循环中为mysql\u fetch\u数组函数创建单选按钮。代码如下:Php 无法选择单选按钮,php,mysql,radio-button,Php,Mysql,Radio Button,我的问题是我不能选择单选按钮。我正在使用php mysql,并在while循环中为mysql\u fetch\u数组函数创建单选按钮。代码如下: <div class="alert alert-info"> <label id="dataFlow"> <?php if($detailPage == TRUE && $detailType == "poll"){ ?> <!-- su
<div class="alert alert-info">
<label id="dataFlow">
<?php if($detailPage == TRUE && $detailType == "poll"){ ?>
<!-- survey part -->
<h3><?php echo $pollData['pollContent']; ?></h3>
<form id="pollForm" method="post" action="">
<p>
<?php while($pollAnswerData = $pollAnswerDataSql->fetch_assoc()) {
echo '<input type="radio" id="' . $pollAnswerData['pollquestionId'] . '" name="pollAnswer" />' . $pollAnswerData['pollquestionContent'] . '<br/>';
} ?>
</p>
<input type="submit" name="submitButton" id="submitButton" value="Gönder"/>
</form>
<?php } else if($detailPage == TRUE && $detailType == "post") { ?>
<h4><?php echo $postData['postContent']; ?></h4>
<?php } else {
listFlowData();
} ?>
</label>
</div>
这里有什么问题?似乎缺少值属性
输入元素(单选或复选框)未选中,但已选中。要在浏览器中显示处于选中状态的元素,必须向元素添加布尔“checked”属性
<input type="radio" checked="checked" id="..." name="..." value="..."/>
请注意,浏览器仅将选中元素的值发送到服务器端脚本。要识别未选中的元素,必须使用内部列表
对于无线电输入,这意味着仅当用户单击其中一个元素(或使用属性进行检查)时,表单请求中将存在命名参数。您可以更改此行代码
echo '<input type="radio" id="' . $pollAnswerData['pollquestionId'] . '" name="pollAnswer" />' . $pollAnswerData['pollquestionContent'] . '<br/>';
echo“”$pollAnswerData['pollquestionContent'].'
;
对这个
echo '<input type="radio" id="' . $pollAnswerData['pollquestionId'] . '" name="pollAnswer" value="' . $pollAnswerData['pollquestionId'] . '"/>' . $pollAnswerData['pollquestionContent'] . '<br/>';
echo“”$pollAnswerData['pollquestionContent'].'
;
希望$pollAnswerData['pollquestionId']是唯一的值。未选择“单选框”,因为未在“单选框”中插入值。您应该插入值,该值必须在每次循环重复时更改
谢谢。在谷歌浏览器中,您可能不会遇到任何问题。在Firefox中,存在一个问题。我发现的问题是你的表单在一个标签内。 去掉标签标签,一切都会好起来的。 即使是非唯一ID也不会在任何浏览器中受到影响(在chrome、Firefox和IE9上测试) 下面是我为您测试的HTML。取消对标签的注释,就会出现问题。希望能有帮助 注意:每个单选按钮的ID故意保持不变,以表明浏览器忽略了这一点
<html>
<head></head>
<body>
<!-- <label id="dataFlow"> -->
<form id="pollForm" method="post" action="">
<input type = "radio" id="rdo1" name = "poll_radio" value = "dsfsr"/>111<br/>
<input type = "radio" id="rdo1" name = "poll_radio" value = "rsddf"/>222<br/>
<input type = "radio" id="rdo1" name = "poll_radio" value = "rsfdf"/>333<br/>
<input type = "radio" id="rdo1" name = "poll_radio" value = "rshdf"/>444<br/>
<input type="submit" name="submitButton" id="submitButton" value="Gender"/>
</form>
<!-- </label> -->
</body>
</html>
111
222
333
444
标签中的整个表单标签…令人惊讶!!!您的程序结构错误。除此之外,当您通过单选按钮提交数据时,您会遇到什么错误?checked=“checked”不是必需的。您可能需要在编辑页面中显示用户已选中或选择的选项。
<html>
<head></head>
<body>
<!-- <label id="dataFlow"> -->
<form id="pollForm" method="post" action="">
<input type = "radio" id="rdo1" name = "poll_radio" value = "dsfsr"/>111<br/>
<input type = "radio" id="rdo1" name = "poll_radio" value = "rsddf"/>222<br/>
<input type = "radio" id="rdo1" name = "poll_radio" value = "rsfdf"/>333<br/>
<input type = "radio" id="rdo1" name = "poll_radio" value = "rshdf"/>444<br/>
<input type="submit" name="submitButton" id="submitButton" value="Gender"/>
</form>
<!-- </label> -->
</body>
</html>