无法获取单选按钮的值

时间:2013-06-16 21:10:22

标签: php forms

我正在构建一个表单来将数据发布到MySQL数据库,我已经完成了所有这些但是每当我测试它时,单个部分中的单选按钮的值都在数据库中显示为0。 因此,例如,这显示了表格中填写的任何内容的正确值。

<div class="indented">
            Stronger?
            <input type="radio" name="q4a" value="1" id="q4aY" />
            <label for="q4aY"><span></span>Yes/ </label>
            <input type="radio" name="q4a" value="0" id="q4aN" />
            <label for="q4aN"><span></span>No</label><br />
            More likely to succeed?
            <input type="radio" name="q4b" value="1" id="q4bY" />
            <label for="q4bY"><span></span>Yes/ </label>
            <input type="radio" name="q4b" value="0" id="q4bN" />
            <label for="q4bN"><span></span>No</label><br />
            More known/visible/recognized?
            <input type="radio" name="q4c" value="1" id="q4cY" />
            <label for="q4cY"><span></span>Yes/ </label>
            <input type="radio" name="q4c" value="0" id="q4cN" />
            <label for="q4cN"><span></span>No</label><br />
            <br />
</div>

但是,无论如何,每次填写时都会返回零。

<table id="section2Table">
            <thead>
                <tr>
                    <th scope="colgroup" colspan="4">Before ELP</th>
                    <th scope="col">Activities that support Entrepreneurship</th>
                    <th scope="colgroup" colspan="4">Now</th>
                </tr>
                <tr>
                    <th>Yearly</th>
                    <th>Quarterly</th>
                    <th>Monthly</th>
                    <th>Weekly</th>
                    <th></th>
                    <th>Yearly</th>
                    <th>Quarterly</th>
                    <th>Monthly</th>
                    <th>Weekly</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td><input type="radio" name="7_1b" value="1" id="1yearlyb" />
                    <label for="1yearlyb"><div align="center"></div></label></td>
                    <td><input type="radio" name="7_1b" value="4" id="1quarterlyb" />
                    <label for="1quarterlyb"><div align="center"></div></label></td>
                    <td><input type="radio" name="7_1b" value="12" id="1montlyb" />
                    <label for="1montlyb"><div align="center"></div></label></td>
                    <td><input type="radio" name="7_1b" value="52" id="1weeklyb" />
                    <label for="1weeklyb"><div align="center"></div></label></td>
                    <td class="q7question">Strategically lead others as a member of an advisory board or board of directors (company or NGO, including JA, chamber)</td>
                    <td><input type="radio" name="7_1n" value="1" id="1yearlyn" />
                    <label for="1yearlyn"><div align="center"><span id="check"></span></div></label></td>
                    <td><input type="radio" name="7_1n" value="4" id="1quarterlyn" />
                    <label for="1quarterlyn"><div align="center"><span id="check"></span></div></label></td>
                    <td><input type="radio" name="7_1n" value="12" id="1montlyn" />
                    <label for="1montlyn"><div align="center"><span id="check"></span></div></label></td>
                    <td><input type="radio" name="7_1n" value="52" id="1weeklyn" />
                    <label for="1weeklyn"><div align="center"><span id="check"></span></div></label></td>
                </tr>

我不确定我在这里缺少什么,发布页面上的PHP代码都是一样的,如果你想看看我会发布它,但所有变量都以相同的方式识别。我很喜欢这方面的一些帮助,因为我对这些东西很陌生。 谢谢!

2 个答案:

答案 0 :(得分:1)

通过w3c validator运行您的HTML。你会发现很多错误。其中之一是(其中不止一个):

value of attribute "ID" invalid: "1" cannot start a name 
    <input type="radio" id="1yearlyb" value="1" name="7_1b">
                            ^
  

125:属性Y的值无效:X无法启动名称

     

您可能违反了此属性的命名约定。例如,id和name属性必须以a开头   信,不是数字。

div内的label似乎也被指出为无效。我建议您修复HTML中的语法错误,然后再从那里重试。

我不知道这是否可以解决您的问题,但标准符合并不是一个坏主意。

这是一个不错的sandbox environment,你可以尝试一下,设置有问题的情况并让我们调试它。

答案 1 :(得分:0)

属性值不是按钮的当前状态。

相反,它是无线电按钮的值,如果它被选中。

示例:如果选择了radiobutton,并且如果定义的值为YES,那么在php中您将收到YES,但如果未选择,则不会收到任何内容。

相关问题