I have a update.jsp in which a member after viewing a display page is allowed to click on the row and then update that particular row. Then a update page will called the data from the database and displayed the data that was entered earlier and allowed the user to make changes and update from there by overwriting the old data.
But, when I use the option for the location and highlighted the desired location choosing from a list of options, and updated, it doesn't update the new location and the old location remains.
I hope someone can advise me what's wrong with my code below:
(Sorry I know some of you will say don't mix the logic with the JSP but now I have no choice because I have yet learnt how to separate the two)
if (request.getParameter("action") != null) { int selectionId = Integer.parseInt(request.getParameter("ID")); String Location = request.getParameter("txtLocations"); <tr> <td>Location</td> <td><select name="txtLocations" id="txtLocations"> <option value="Adx">Adx <option value="Alj">Alj <option value="AMK">AMK <option value="Bal">Bal </tr> String sql = "UPDATE members SET strLocation = '" + Location +"' where id= " + selectionId; <html> Member Id = <%= request.getParameter("ID")%> Successfully Updated ! <br><br> <a href="DisplayData.jsp"> Return to Member Display</a> </html> <%} else {%> <% String strLocation = null; rs = stmt.executeQuery("SELECT * from members where members.ID = " + selectionId + ""); if (rs.next()) { strLocation = rs.getString("strLocation"); } else { strLocation = "Unknown."; } %> <html> <form action="update.jsp" method ="post" name="update"> </center> <input type="hidden" value="list" name="action"> <input type="hidden" value=<%= request.getParameter("ID")%> name="ID"> <td>Location</td> <td><select name="txtLocations" id="txtLocations"> <option value="Adx">Adx <option value="Alj">Alj <option value="AMK">AMK <td align="right"> <input type="submit" id="btnSubmit" name="Update Member" value="Update Member<%= request.getParameter("ID")%>"> </td></tr> </table> <a href ="DisplayData.jsp">Return to Member Display Page</a> <a href ="logout.jsp">Log Out</a> </div> <% stmt.close(); { out.close(); } }%> </body> </html>
Many thanks.