如何使用PHP的单选按钮 [英] How to use a radio button with php

查看:152
本文介绍了如何使用PHP的单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


有人可以告诉我或者给我看一个如何在php中使用多个单选按钮的例子吗?


我有一个带有1个文本框和4个单选按钮的表单。我想要做的是拥有一个用户,输入一个搜索字符串,然后检查一个单选按钮,该按钮将与数据库中的一个字段相对应。我遇到的问题是所有单选按钮的输入名称必须相同,以确保只选中一个按钮。所有四个按钮必须具有相同的名称才能在html中的同一组中。


如果我使所有名称相同,那么我如何区分一个POST值和另一个?我想的可能是从html按钮'的价值,但我不能让PHP看到它。


有人可以提供样品或我需要去的方向在?


谢谢,


Frank

Hi everyone,

Can somebody please tell me or maybe show me an example of how to use multiple radio buttons in php?

I have a form with 1 textbox and 4 radio buttons. What I want to do is have a user, type in a search string and then check a radio button that will cooraspond to a field in a database. The problem I am having is that the input name must be the same for all of the radio buttons to ensure that only one button is checked. All four buttons must have the same name to be in the same group within the html.

If I make all of the names the same, then how do I differentiate between one POST value and another? I was thinking that maybe from the html button''s value but I can''t get php to see it.

Can someone please provide a sample or the direction I need to go in?

Thanks,

Frank

推荐答案

你怎么说的是在变量的值中(也在输入标记的value属性中设置)。看下面的单选按钮:

[html]

< input type =" radio"命名= QUOT;无线电"值= QUOT;无线电" />

< input type =" radio"命名= QUOT;无线电"值= QUOT;第二广播电台" />

< input type =" radio"命名= QUOT;无线电"值= QUOT; radio3" />

[/ html]

[php] echo
How you tell is in the value of the variable (also set in the value attribute of the input tag). Look at the radio buttons below:
[html]
<input type="radio" name="radio" value="radio" />
<input type="radio" name="radio" value="radio2" />
<input type="radio" name="radio" value="radio3" />
[/html]
[php]echo


_POST [''radio'']; [/ php如果检查了第一个单选按钮,则上面的代码将输出无线电,如果检查了第二个单选按钮,则输出radio2的相同代码将输出radio2。如果第三个被检查,则相同的代码将输出radio3。


所以基本上,变量有3个不同的可能值,取决于你检查过哪个单选按钮。
_POST[''radio''];[/php]
If the first radio button was checked the code above would output "radio", if the second was checked the very same code would output "radio2" and if the third was checked the very same code would output "radio3".

So basically, one variable 3 different possible values for that variable depending what which radio button you''ve checked.


我假设你可以只需将单选按钮的值设置为与表的列名对应即可...


[html]

< input type =" ;文本"名称= QUOT;的textBox" />

< input type =" radio"名称= QUOT; UPDATEFIELD"值= QUOT;名称" />

< input type =" radio"名称= QUOT; UPDATEFIELD"值= QUOT;地址]按钮/>

< input type =" radio"名称= QUOT; UPDATEFIELD"值= QUOT; phoneNumber的" />

[/ html]


[php]
I assume you could just set the value of the radio buttons to correspond with the column name of your table so...

[html]
<input type="text" name="textBox" />
<input type="radio" name="updateField" value="name" />
<input type="radio" name="updateField" value="address" />
<input type="radio" name="updateField" value="phoneNumber" />
[/html]

[php]


这篇关于如何使用PHP的单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆