dongliao3450 2018-01-17 17:10
浏览 34
已采纳

如果设置单选按钮如何获取

So i ve got 3 radio buttons in a html document. Then i simply try to get if one of the buttons is set and then to print a message for one of the ticked buttons. They all are in a form. my buttons are:

echo "<table border=0>";
                echo "
                    <tr>
                        <td>
                            <input type=radio name=sg value=admin /> Administrator
                        </td>
                    </tr>
                ";
                echo "
                    <tr>
                        <td>
                            <input type=radio name=sg value=operator /> Operator
                        </td>
                    </tr>
                ";
                echo "
                    <tr>
                        <td>
                            <input type=radio name=sg value=member checked=checked /> member
                        </td>
                    </tr>
                ";
        echo "</table>";

The way i try to get them is:

if(isset($_GET['member'])) {
            echo "m is set!";
        }
        if(isset($_GET['admin'])) {
            echo "a is set!";
        }
        if(isset($_GET['operator'])) {
            echo "op is set!";
        }

This doesnt print anything, means none of the statements in the if clauses are true. How do i get them?

  • 写回答

1条回答 默认 最新

  • dsbo44836129 2018-01-17 17:16
    关注

    You access the value of the input incorrectly, like this:

    if(isset($_GET['member']))
    

    instead of the name of the HTML element, like this:

      if(isset($_GET['sg'])){ 
          if($_GET['sg'] == "member") {
            echo "m is set!";
         }
         if($_GET['sg'] == "admin") {{
            echo "a is set!";
         }
         if($_GET['sg'] == "operator"){
            echo "op is set!";
         }
      }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址