我有一个表格,用户从中选择一个答案,然后我将选择的答案的值插入数据库中的3个值,但是有两个问题1)我插入了3行,但是我在mysql中只找到一个2)在mysql中,selected_answer值始终为空,当我输入数字而不是selected_answer时,它将起作用!
<form action ="Thanks.jsp" method ="get">
<p><input type="radio" name="ans" value= <%=answers_id[0]%>/><%=answers[0]%></p>
<p><input type="radio" name="ans" value=<%=answers_id[1]%>/><%=answers[1]%></p>
<p><input type="radio" name="ans" value=<%=answers_id[2]%>/><%=answers[2]%></p>
<p><input type="submit" value="submit"/>
</form>
<%
String chosen_answer = request.getParameter("ans");
//in this loop i'm removing the chosen_answer from the array
for (int i = 0; i < answers_id.length; i++) {
if (answers_id[i] == chosen_answer) {
// shifting elements
for (int j = i; j < answers_id.length - 1; j++) {
answers_id[j] = answers_id[j + 1];
}
break;
}
}
// i will make the first aid is the answer that is chosen to know if he answer it right or wronge
String queryString3 = "INSERT INTO stud_ans VALUES("
+ "'" + ID + "',"
+ "'" + 1 + "',"
+ "'" + 7 + "') , (" + "'" + ID + "',"
+ "'" + 1 + "',"
+ "'" + 7 + "'),(" + "'" + ID + "',"
+ "'" + 1 + "',"
+ "'" + 7 + "')";
Stmt.executeUpdate(queryString3);
Con.close();
RS.close();
} catch (Exception cnfe) {
System.err.println("Exception: " + cnfe);
}
%>