2012-07-16 2 views
1

제출할 때 라디오 버튼에서 데이터를 가져오고 싶지만, 라디오에서 값을 가져올 수없는 이유를 모르겠습니다.라디오 버튼에서 값을 가져올 수 없습니다.

내 코드

<?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

사용 $_POST 대신 $_GET 양식에서 데이터를 얻을 수 있습니다. 또는 당신은 $_GET를 사용하는 $_POST['choice'] 또는 $_REQUEST['choice'].

+0

내 바보 같은 실수. 감사합니다. 제임스 – strc

+0

하지 마십시오. 이제까지. 용도. '$ _REQUEST'. –

0

$_REQUEST에게 also.Replace $_GET['choice']를 사용할 수 있지만 형태는 을 게시합니다. $choice = $_POST['choice']을 사용하십시오.

0

귀하의 양식은 POST이지만 찾으시는 분은 $_GET[]입니다. 대신 $_POST['choice']에서 찾으십시오.

0

양식 데이터에 대한 액세스 변수와 일치해야합니다 양식 요소의 method :

<form method="post"> 
// Need to use the $_POST[] array to access values 

<form method="get"> 
// Use the $_GET[] array to access values 

$ _GET는 일반적으로 URL 문자열에 사용됩니다. 일반적으로 양식의 방법을 post으로 원할 것입니다.

0

양식은 당신이 _POST이 같은 글로벌 배열을 사용하는 것보다, POST로 설정 방법을 속성이있는 경우 - <?php $choice = $_POST['choice']; ?>

관련 문제