forked from pipspritam/Full-Stack-Shopping-website-with-jsp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuy_now.jsp
125 lines (115 loc) · 4.58 KB
/
buy_now.jsp
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="navbar.jsp" %>
<%@ include file="dbconnect.jsp" %>
<title>Buy Now</title>
<link rel="stylesheet" href="./css/buy_now.css">
<script type="text/javascript">
function validate()
{
if(address.value.trim()=="")
{
alert("address cann't be empty");
address.style.border = "solid 3px red";
return false;
}
else if(del_name.value.trim()=="")
{
alert("Name cann't be empty");
del_name.style.border = "solid 3px red";
return false;
}
else if(del_email.value.trim()=="")
{
alert("Email cann't be empty");
del_email.style.border = "solid 3px red";
return false;
}
else if(del_phone.value.trim()=="")
{
alert("Phone number cann't be empty");
del_phone.style.border = "solid 3px red";
return false;
}
else if(del_pincode.value.trim()=="")
{
alert("Pincode cann't be empty");
del_pincode.style.border = "solid 3px red";
return false;
}
else
{
return true;
}
}
</script>
</head>
<body>
<%
String id = request.getParameter("ID");
try{
Statement stmt=con.createStatement();
ResultSet rs=stmt.executeQuery("select * from item where product_id = '" + id + "'");
Statement stmt1=con.createStatement();
ResultSet rs1=stmt1.executeQuery("select * from users where email = '" + (String)session.getAttribute("email") + "'");
rs1.next();
rs.next();
int final_price = (rs.getInt(3)*(100 - rs.getInt(6)))/100;
String imgName = rs.getString(1) + ".jpg";
String img_path = "./image/";
%>
<div class="container">
<form class="order-div" onsubmit="return validate();" action="./process_buy_now.jsp" method="POST">
<h1>Order Details</h1>
<div class="product-details-div">
<div class="product-img-div">
<input type="hidden" name="ID" value="<%= id %>">
<img src="<%= img_path+imgName %>" alt="./image/product-1.jpg" onerror="this.onerror=null; this.src='./image/default.jpg'">
</div>
<div class="product-details">
<h3><%= rs.getString(2) %></h3>
<p>Price: <span>₹</span><%= pretty_print_price(Integer.toString(final_price)) %> </p>
<div class="discount-price">
<span>₹</span><strike>500</strike><span>  5% off</span>
</div>
<p>Quantity: <input type="number" min="1" name="quantity" id="quantity" value="1" max="9"></p>
</div>
</div>
<div class="address-div">
<h3>Delivery Address</h3>
<div class="input-box">
<label for="name">Name</label>
<input type="text" name="del_name" id="del_name" value="<%= rs1.getString(1)%>">
</div>
<div class="input-box">
<label for="email">Email</label>
<input name="del_email" type="email" id="del_email" value="<%= rs1.getString(2)%>">
</div>
<div class="input-box number">
<label for="phone">Phone</label>
<input type="number" name="del_phone" id="del_phone" value="<%= rs1.getString(3)%>">
</div>
<div class="input-box number">
<label for="pincode">Pincode</label>
<input name="del_pincode" type="number" id="del_pincode" value="<%= rs1.getString(6)%>">
</div>
<div class="input-box">
<label for="address">Address</label>
<textarea name="address" id="address" cols="30" rows="6"><%= rs1.getString("address") %></textarea>
</div>
</div>
<div class="procced-btn-div">
<button formaction="index.jsp">Cancel</button>
<input type="submit" value="PROCESS ORDER">
</div>
</form>
</div>
<%
con.close();
}
catch (Exception e) {
}
%>
</body>
</html>