Reputation: 79
In the picture in below, when user press submit button, application inserting choosen number to to database. But it does not work for activityid number. After pressing submit button, activityid is returning null and buy is returning choosen number. How can I do insert correct activityid on database
music.jsp
<table border="1" width="30%" height="30%">
<th><font color='#D18603'>ActivityID</font>
<th><font color='#D18603'>Type</font></th>
<th><font color='#D18603'>Description</font></th>
<th><font color='#D18603'>City</font></th>
<th><font color='#D18603'>Location</font></th>
<th><font color='#D18603'>Date</font></th>
<th><font color='#D18603'>Price</font></th>
<th><font color='#D18603'>Buy</font>
<%
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/users", "users", "123");
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from activities where type='müzik'");
while (rs.next()) {
out.println("<tr>");
out.println("<td>" + rs.getString("id")+"</td>");
out.println("<td>" + rs.getString("type")+ "</td>");
out.println("<td>" + rs.getString("description")+ "</td>");
out.println("<td>" + rs.getString("city") + "</td>");
out.println("<td>" + rs.getString("location")+ "</td>");
out.println("<td>" + rs.getString("date") + "</td>");
out.println("<td>" + rs.getString("price") + "</td>");
out.println("<td><b><form action='reservations.jsp'><select name='buy'><option value='1'>1</option><option value='2'>2</option><option value='3'>3</option><option value='4'>4</option><option value='5'>5</option></select><input type='submit' value='Submit'></form></b>");
out.println("</tr>");
}
st.close();
%>
Reservation.jsp
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ page import ="java.sql.*" %>
<%
String username = (String) request.getSession().getAttribute("username");
Class.forName("org.apache.derby.jdbc.ClientDriver").newInstance();
Connection con = DriverManager.getConnection("jdbc:derby://localhost:1527/users", "users", "123");
String sorgu = "INSERT INTO reservation(id,username,buy) VALUES ('" + request.getParameter("id") + "', '" + username + "','" + request.getParameter("buy") + "') ";
java.sql.Statement st = con.createStatement();
int rowNum = st.executeUpdate(sorgu);
response.sendRedirect("paypal.html");
st.close();
%>
Upvotes: 0
Views: 48
Reputation: 35011
You need to get the tag around all data in each row, and add (hidden) form tags to each column so that all the data gets included in the form submission. For the sake of clarity, I've eliminated everything but how to organize the form tags and how to include the "id" in the form submission
rs = st.executeQuery("select * from activities where type='müzik'");
while (rs.next()) {
out.println("<tr>");
out.println("<form action='reservations.jsp'>");
out.println("<td>" + rs.getString("id") + "<input type='hidden' name='id' value='" + td.getString("id")+"'></td>");
out.println("<td><input type='submit' value='Submit'></form></b></td>");
out.println("</td></tr>");
}
st.close();
Upvotes: 1