I have written a code where the admin has the access to change the general users from active to inactive and vice-versa. So I want to update the database if the radio button is changed from active to inactive.
Here is the code:
<%
while (rs.next()) {
String firstname = rs.getString("firstname");
String lastname = rs.getString("lastname");
String email = rs.getString("email");
String password = rs.getString("password");
String age = rs.getString("age");
String sex = rs.getString("sex");
String haddress = rs.getString("haddress");
String oaddress = rs.getString("oaddress");
String phonenumber = rs.getString("phonenumber");
String flag = rs.getString("flag");
Statement stmt1 = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
%>
<tr>
<td>
Name: <% out.println(firstname); %> <% out.println(lastname); %>
</td>
<td>
<% if (flag.equals("A")){ %>
Active: <input type="radio" value="A" name="<% out.println(email); %>" onclick="<% stmt1.executeUpdate("update assignment set flag='A' where email='"+email+"'");
System.err.println("A"+email); %>
alert('changed to active');" checked>
Inactive: <input type="radio" value="I" name="<% out.println(email); %>" onclick="<% stmt1.executeUpdate("update assignment set flag='I' where email='"+email+"'");
System.err.println("I"+email); %>
alert('changed to inactive');">
<%
}else if(flag.equals("I")){%>
Active: <input type="radio" value="A" name="<% out.println(email); %>" onclick="<% stmt1.executeUpdate("update assignment set flag='A' where email='"+email+"'");
System.err.println("A"+email); %>
alert('changed to active');">
Inactive: <input type="radio" value="I" name="<% out.println(email); %>" onclick="<% stmt1.executeUpdate("update assignment set flag='I' where email='"+email+"'");
System.err.println("I"+email); %>
alert('changed to inactive');" checked>
But in output, when I change one radio button, all the queries run automatically, updating the database to I for all the data in the DB.