Hello everyone
I am doing my project on a shopping cart. i have a little problem! ive got 2 tables..products and tempcart. The products table contains the fields idnumber and all the rest of the product information (such as title, description). The tempcart table has 2 fields. sessionid and idnumber. Each time a user selects an item, the idnumber and the sessionid is inserted into the tempcart. It works so far!! however the problem is i want to find out what products has that particular user selected during that session not products selected by all users. At the moment when the user selects a product they want to purchase i get a blank page of the cart and does not show the product details. the code i am usinmg is as follows:
<%@ page import="java.sql.*, java.util.*, java.io.* " session="true" %>
<%
Class.forName("com.mysql.jdbc.Driver").newInstance();
java.sql.Connection con1 = null;
Statement stmt1 = null;
ResultSet rs1 = null;
String queryStr1 = null;
String usernamereg1 = request.getParameter("usernamereg");
String strsessionid = request.getParameter("sessionid");
try{
con1 = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/databasename?user=user&password=password");
stmt1 = con1.createStatement();
queryStr1 = "select * from products prod, tempcart cart where prod.idnumber=cart.idnumber AND cart.sessionid = '"+ strsessionid +"'";
rs1 = stmt1.executeQuery(queryStr1);
%>
<html>
User <font color = "red"><b><%=usernamereg1%></font></b> Logged In
<center>
<font size=5>Shopping Cart</font>
</center>
<center>
<br>
<form action="deletecart.jsp" method=post>
<br>
<table cellpadding=2 cellspacing=2 align="right" border=1 width="70%">
<tbody>
<tr>
<th>Select</th>
<th>Title</th>
<th>Description</th>
<th>Category</th>
<th>Price</th>
<th>Image</th>
<th>Remove</th>
</tr>
<%
while (rs1.next())
{
String idnumber = rs1.getString(1);
String title = rs1.getString(2);
String description = rs1.getString(3);
String category = rs1.getString(5);
String price = rs1.getString(6);
String image = rs1.getString(7);
%>
<tr><td valign = 'Top'><input type="radio" name="dvddownload" value="<%=idnumber%>"</br></td>
<td valign = 'Top'> <%=title%> </td>
<td valign = 'Top'> <%=description%> </td>
<td valign = 'Top'> <%=category%> </td>
<td valign = 'Top'> <%=price%> </td>
<td valign = 'Top'> <img src="<%=image%>" border=1 width=90 height=120"> </td>
<td valign = 'Top'><input type="submit" name="removetempcart" value="Remove" </td>
</tr>
<%
} // end while ()
}catch(SQLException s) {%> <%= s%> <% }
finally{
//clean up.
try{
if (rs1!=null) rs1.close();
if (stmt1!=null) stmt1.close();
if (con1!=null) con1.close();
}catch (SQLException s) {}
}
%>
</table>
<br>
<td align=center colspan=2>
</td>
</tr>
</center>
</form>
<form action="check2.html" method=post>
<input type="Submit" value="Checkout">
</form>
<form action="list.jsp" method=post>
<input type="submit" value="Continue Shopping">
<input type="hidden" name="sessionid" value="<%=session.getId()%>"
</form>
</html>
i have got the sessionid as a hidden field, convert it to a string and compare it in the select statement.but it still doesnt work. I would really appreciate if anyone can help me with this.
thanks shaz!!!