[go: up one dir, main page]

Menu

[773754]: / web / cart.jsp  Maximize  Restore  History

Download this file

49 lines (39 with data), 1.8 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<%@page contentType="text/html" pageEncoding="UTF-8" import="java.sql.*"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Cart</title>
</head>
<body>
<%
int qty=Integer.parseInt(request.getParameter("qt1"));
String model=request.getParameter("model");
int price=Integer.parseInt(request.getParameter("price"));
int total=qty*price;
try{
Class.forName("com.mysql.jdbc.Driver");
Connection c=DriverManager.getConnection("jdbc:mysql://localhost/products","root","");
PreparedStatement ps=c.prepareStatement("insert into cart(Model_Name,Quantity,selling_price,total,status,username) values(?,?,?,?,?,?)");
ps.setString(1,model);
ps.setString(2,""+qty);
ps.setString(3, ""+price);
ps.setString(4,""+ total);
ps.setString(5,"NO");
ps.setString(6,session.getAttribute("user_name").toString());
int i=ps.executeUpdate();
if(i>0){
out.println("<script>alert('Product Added into Cart Successfully');window.location.assign('product_view.jsp');</script>");
}
else
{
out.println("<script>alert('Sorry, something happened wrong');window.location.assign('product_view.jsp');</script>");
}
Statement s=c.createStatement();
ResultSet rs1=s.executeQuery("select cart_id from cart");
String cartid=rs1.getString(1);
session.setAttribute("cid",cartid);
}catch(Exception e){out.println(e);}
%>
</body>
</html>