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>
5 个解决方案
#1
5
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'].
使用$ _POST而不是$ _GET从表单中获取数据。或者您也可以使用$ _REQUEST还使用$ _POST ['choice']或$ _REQUEST ['choice']来替换$ _GET ['choice']。
#2
0
You are using $_GET
, but the form is posted. Use $choice = $_POST['choice']
.
您正在使用$ _GET,但表单已发布。使用$ choice = $ _POST ['choice']。
#3
0
Your form is POST
but you're looking for it in $_GET[]
. Look for it in $_POST['choice']
instead.
您的表单是POST,但您在$ _GET []中查找它。在$ _POST ['choice']中寻找它。
#4
0
The method
of your form element should match the variable you access for the form data:
表单元素的方法应该与您为表单数据访问的变量匹配:
<form method="post">
// Need to use the $_POST[] array to access values
<form method="get">
// Use the $_GET[] array to access values
$_GET is typically used for url strings. Usually you will want the method of your form to be post
.
$ _GET通常用于url字符串。通常,您需要发布表单的方法。
#5
0
If your form has attribute method set to POST, than you should use _POST global array like this - <?php $choice = $_POST['choice']; ?>
如果你的表单将属性方法设置为POST,那么你应该像这样使用_POST全局数组 -
#1
5
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'].
使用$ _POST而不是$ _GET从表单中获取数据。或者您也可以使用$ _REQUEST还使用$ _POST ['choice']或$ _REQUEST ['choice']来替换$ _GET ['choice']。
#2
0
You are using $_GET
, but the form is posted. Use $choice = $_POST['choice']
.
您正在使用$ _GET,但表单已发布。使用$ choice = $ _POST ['choice']。
#3
0
Your form is POST
but you're looking for it in $_GET[]
. Look for it in $_POST['choice']
instead.
您的表单是POST,但您在$ _GET []中查找它。在$ _POST ['choice']中寻找它。
#4
0
The method
of your form element should match the variable you access for the form data:
表单元素的方法应该与您为表单数据访问的变量匹配:
<form method="post">
// Need to use the $_POST[] array to access values
<form method="get">
// Use the $_GET[] array to access values
$_GET is typically used for url strings. Usually you will want the method of your form to be post
.
$ _GET通常用于url字符串。通常,您需要发布表单的方法。
#5
0
If your form has attribute method set to POST, than you should use _POST global array like this - <?php $choice = $_POST['choice']; ?>
如果你的表单将属性方法设置为POST,那么你应该像这样使用_POST全局数组 -