1

不幸的是,我无法准确地找到我在网上寻找的东西来解决这个问题。

无论如何,我有三个单选按钮,我需要将从列表中选择的单个按钮的选择推送到 MySQL。

目前使用以下作为我的单选按钮并提交:

   <input class="radiobutton" type="radio" name="1" id="1">1</div>
   <input class="radiobutton" type="radio" name="2" id="2">2</div>
   <input class="radiobutton" type="radio" name="3" id="3">3</div>
   <input type="submit" name="submit" value="Update">`

有人可以帮助我获取所选单选按钮并将其插入 MySQL 的语法吗?

语法的一个例子是 UPDATE tblwhatever.setting SET value='$x' where setting='Y';

4

2 回答 2

1

考虑以下:

<input class="radiobutton" type="radio" name="radio" id="1" value="1" onclick="document.getElementById('2').checked = false;"/>
<input class="radiobutton" type="radio" name="radio" id="2" value="2" onclick="document.getElementById('1').checked = false;"/>

请注意,我给了他们相同的name属性。提交表单后,我们将检索$_POST['radio']value确定选择了哪个单选按钮。如果选中,该onclick属性将取消选中另一个单选按钮。例如:如果选中单选按钮,则id="1"取消选中id="2"

于 2012-10-24T02:22:00.433 回答
1
    <form method='POST' >
<input class="radiobutton" type="radio" 

name="radio" id="1" value='1' checked>
       <input class="radiobutton" type="radio" 

name="radio" id="2" value='2'>
       <input class="radiobutton" type="radio" 

name="radio" id="3" value='3'>
       <input type="submit" name="submit" 

value="Update">`

</form>

在 php 代码中应该是这样的:

<?
    $radio = $_POST['radio'];
    $query = mysql_query('update "your table" set column1=$radio WHERE some_column=some_value);
?>
于 2012-10-24T02:38:26.293 回答