2011-10-13 4 views
0

나는 라디오 버튼으로 두 가지 옵션이 질문의 페이지가 있습니다. 각 질문은 양식 태그가 있습니다. 이제는 사용자가 데이터베이스에서 확인한 값을 저장하고 싶습니다. 에있는 단일 함수 PHP. 어떻게해야합니까? 다음과 같이 내 HTML 코드는 다음과 같습니다db (PHP) 라디오 버튼의 값을 기록

<li>Question1 </li> 
    <br /><form>A.  
    <input type="radio" name="radio" id="1ARadioButton" value="1ARadioButton" /> 
    <label for="1ARadioButton">Answer1</label><br /><br /> 
    B.  
    <input type="radio" name="radio" id="1BRadioButton" value="1BRadioButton" /> 
    <label for="1BRadioButton"> Answer2</label> 
    </form><br /><br /> 
    <li>Question2</li> 
    <br /><form>A. 
    <input type="radio" name="radio" id="2ARadioButton" value="2ARadioButton" /> 
    <label for="2ARadioButton">Answer1</label> 
    <br /><br /> 
    B.  
    <input type="radio" name="radio" id="2BRadioButton" value="2BRadioButton" /> 
    <label for="2BRadioButton">Answer2</label> 
    </form><br /><br /> 
    <li>Question3</li> 
    <br /><form>A.  
    <input type="radio" name="radio" id="3ARadioButton" value="3ARadioButton" /> 
    <label for="3ARadioButton">Answer1</label> 
    <br /><br /> 
    B.  
    <input type="radio" name="radio" id="3BRadioButton" value="3BRadioButton" /> 
    <label for="3BRadioButton">Answer2</label> 
    </form><br /><br /> 

답변

2

당신은 모든 라디오 버튼에 같은 ​​이름을 가지고, 그래서 당신은 체크 해제 년대 LAST 라디오 버튼의 값을받을거야. 모든 질문 (보통 C 임)에 대해 동일한 대답을 녹음하게 될 것입니다.

요소 ID는 이고 양식 제출에는입니다. DOM 조작에만 사용됩니다. HTML 양식에서는 namevalue 유형 속성 만 양식 제출 프로세스와 관련됩니다.

은 당신이해야하는 것입니다 : 데이터베이스에 저장에 관해서는

Question 1: 
    <input type="radio" name="question1" value="option_A" /> 
    <input type="radio" name="question1" value="option_B" /> 
Question 2: 
    <input type="radio" name="question2" value="option_A" /> 
    <input type="radio" name="question2" value="option_B" /> 
etc... 

, 즉 데이터베이스에 다른 형태의 데이터를 저장 동일합니다. $_POST['question1'] 또는 무엇이든간에 라디오의 값을 가져오고 일반적인 이스케이프/쿼리 작성/삽입을 수행합니다.

관련 문제