I have created a code that allows the admin to toggle a user's status between active and inactive using radio buttons. The technologies I have used for this project are JSP, MySQL, and JS.
admin.jsp:
<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); %>" id="<% out.println(email); %>" onchange="pageupdatecta('<% out.println(email); %>', this.value);" checked>
Inactive: <input type="radio" value="I" name="<% out.println(email); %>" id="<% out.println(email); %>" onchange="pageupdatecti('<% out.println(email); %>', this.value);">
<%
}else if(flag.equals("I")){%>
Active: <input type="radio" value="A" name="<% out.println(email); %>" id="<% out.println(email); %>" onchange="pageupdatecta('<% out.println(email); %>', this.value);">
Inactive: <input type="radio" value="I" name="<% out.println(email); %>" id="<% out.println(email); %>" onchange="pageupdatecti('<% out.println(email); %>', this.value);" checked>
<%
} %>
<script type="text/javascript">
function pageupdatecta(emailid, optedval) {
location.href='changeToActive.jsp?email='+emailid+'&optedval='+optedval;
}
function pageupdatecti(emailid, optedval) {
location.href='changeToInactive.jsp?email='+emailid+'&optedval='+optedval;
}
</script>
changeToActive.jsp:
try{
Class.forName("com.mysql.jdbc.Driver");
System.err.println("Driver loaded!");
Connection con = DriverManager.getConnection(
"jdbc:mysql://localhost/work", "root", "MyNewPass");
System.err.println("Database Connected..");
Statement stmt = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,
ResultSet.CONCUR_READ_ONLY);
stmt.executeUpdate("update assignment set flag='A' where email='"+email+"'");
System.err.println("A"+email);
}
I'm looking for guidance on how to retrieve values from the function and troubleshoot my code. Can you assist with this?