无法从单选按钮获取价值 [英] Can't get value from radio button

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

问题描述

我想在提交时从单选按钮中获取数据,但
我不知道为什么我无法从广播中获得它的价值。



我的代码

 <?php 
$ choice = $ _GET ['choice'];
?>

< html>
< head>
< / head>
< body>
< form action =index.phpmethod =POST>
< table align =center>
< tr>< td>请选择< / td>< / tr>
< tr>< td>< input type =radioname =choicevalue =0> aaaa< / td>< / tr>
< tr>< td>< input type =radioname =choicevalue =1> bbbb< / td>< / tr>
< tr>< td>< input type =radioname =choicevalue =2> cccc< / td>< / tr>
< tr>< td>< input type =radioname =choicevalue =3> dddd< / td>< / tr>
< tr>< td>< input type =submitvalue =submit>< / td>< / tr>
< / table>
<?php echo$ choice;?>
< / form>
< / body>
< / html>


解决方案使用 $ _ POST 代替 $ _ GET 从表单获取数据。或者您也可以使用 $ _ REQUEST 。用 $替换 $ _ GET ['choice'] _POST ['choice'] $ _ REQUEST ['choice']。


I want to get the data from radio button when I submit it, but I don't know why I can't get the value from radio it.

My code

<?php
   $choice = $_GET['choice'];
?>

<html>
<head>
</head>
<body>
    <form action="index.php" method="POST">
    <table align="center">
        <tr><td>Please select</td></tr>
        <tr><td><input type="radio" name="choice" value="0">aaaa</td></tr>
        <tr><td><input type="radio" name="choice" value="1">bbbb</td></tr>
        <tr><td><input type="radio" name="choice" value="2">cccc</td></tr>
        <tr><td><input type="radio" name="choice" value="3">dddd</td></tr>
        <tr><td><input type="submit" value="submit"></td></tr>
    </table>
             <?php echo"$choice";?>
    </form>
</body>
</html>

解决方案

Use $_POST Instead of $_GET to get data from form. Or you can use $_REQUEST also.Replace $_GET['choice'] with $_POST['choice'] or $_REQUEST['choice'].

这篇关于无法从单选按钮获取价值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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