在表单中显示单选按钮值

时间:2022-10-08 13:43:21

In this code in php, don´t show the values of radio buttons, echo don´t work

在PHP的这段代码中,不要显示单选按钮的值,echo不起作用

<html>
    <head>
        <title>Probando radio</title>
    </head>
    <body>
    <form  method="POST">
        <input type="radio" name="sexo" value="m" checked>Mujer
        <input type="radio" name="sexo" value="h">Hombre
    </form>
    <? php
       $sexo = $_POST['sexo'];
      // print ($sexo);
      echo $sexo;
    ?>
    </body>
</html>

2 个解决方案

#1


specify the form action and add a submit button. upon submit, $_POST['sexo'] should contain your result (m or h)

指定表单操作并添加提交按钮。提交后,$ _POST ['sexo']应包含您的结果(m或h)

#2


This is not a recommended fix, but it will work:

这不是推荐的修复,但它可以工作:

Change:

 <form  method="POST">

To:

 <form action="#"  method="post">

NOTE: Technically method should be lower case. It's an XHTML requirement. You would be penalized by W3C mobileOK validation.

注意:技术方法应该是小写的。这是XHTML的要求。您将受到W3C mobileOK验证的惩罚。

#1


specify the form action and add a submit button. upon submit, $_POST['sexo'] should contain your result (m or h)

指定表单操作并添加提交按钮。提交后,$ _POST ['sexo']应包含您的结果(m或h)

#2


This is not a recommended fix, but it will work:

这不是推荐的修复,但它可以工作:

Change:

 <form  method="POST">

To:

 <form action="#"  method="post">

NOTE: Technically method should be lower case. It's an XHTML requirement. You would be penalized by W3C mobileOK validation.

注意:技术方法应该是小写的。这是XHTML的要求。您将受到W3C mobileOK验证的惩罚。