Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <%--
- Document : cart
- Created on : Dec 19, 2017, 12:09:06 AM
- Author : Sam
- --%>
- <%@page import="java.sql.Array"%>
- <%@page import="java.sql.ResultSet"%>
- <%@page import="java.sql.Statement"%>
- <%@page import="java.sql.DriverManager"%>
- <%@page import="java.sql.Connection"%>
- <%
- String order1 = "";
- if (((String) session.getAttribute("order1")) != null) {
- order1 = (String) session.getAttribute("order1");
- }
- String qty1 = "";
- if (((String) session.getAttribute("qty1")) != null) {
- qty1 = (String) session.getAttribute("qty1");
- }
- String order2 = "";
- if (((String) session.getAttribute("order2")) != null) {
- order2 = (String) session.getAttribute("order2");
- }
- String qty2 = "";
- if (((String) session.getAttribute("qty2")) != null) {
- qty2 = (String) session.getAttribute("qty2");
- }
- String order3 = "";
- if (((String) session.getAttribute("order3")) != null) {
- order3 = (String) session.getAttribute("order3");
- }
- String qty3 = "";
- if (((String) session.getAttribute("qty3")) != null) {
- qty3 = (String) session.getAttribute("qty3");
- }
- String order4 = "";
- if (((String) session.getAttribute("order4")) != null) {
- order4 = (String) session.getAttribute("order4");
- }
- String qty4 = "";
- if (((String) session.getAttribute("qty4")) != null) {
- qty4 = (String) session.getAttribute("qty4");
- }
- String order5 = "";
- if (((String) session.getAttribute("order5")) != null) {
- order5 = (String) session.getAttribute("order5");
- }
- String qty5 = "";
- if (((String) session.getAttribute("qty5")) != null) {
- qty5 = (String) session.getAttribute("qty5");
- }
- String order6 = "";
- if (((String) session.getAttribute("order6")) != null) {
- order6 = (String) session.getAttribute("order6");
- }
- String qty6 = "";
- if (((String) session.getAttribute("qty6")) != null) {
- qty6 = (String) session.getAttribute("qty6");
- }
- String order7 = "";
- if (((String) session.getAttribute("order7")) != null) {
- order7 = (String) session.getAttribute("order7");
- }
- String qty7 = "";
- if (((String) session.getAttribute("qty7")) != null) {
- qty7 = (String) session.getAttribute("qty7");
- }
- String order8 = "";
- if (((String) session.getAttribute("order8")) != null) {
- order8 = (String) session.getAttribute("order8");
- }
- String qty8 = "";
- if (((String) session.getAttribute("qty8")) != null) {
- qty8 = (String) session.getAttribute("qty8");
- }
- String order9 = "";
- if (((String) session.getAttribute("order9")) != null) {
- order9 = (String) session.getAttribute("order9");
- }
- String qty9 = "";
- if (((String) session.getAttribute("qty9")) != null) {
- qty9 = (String) session.getAttribute("qty9");
- }
- String order10 = "";
- if (((String) session.getAttribute("order10")) != null) {
- order10 = (String) session.getAttribute("order10");
- }
- String qty10 = "";
- if (((String) session.getAttribute("qty10")) != null) {
- qty10 = (String) session.getAttribute("qty10");
- }
- double subtotal1 = 0.0;
- double subtotal2 = 0.0;
- double subtotal3 = 0.0;
- double subtotal4 = 0.0;
- double subtotal5 = 0.0;
- double subtotal6 = 0.0;
- double subtotal7 = 0.0;
- double subtotal8 = 0.0;
- double subtotal9 = 0.0;
- double subtotal10 = 0.0;
- %>
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>Order Cart</title>
- </head>
- <body>
- <h1>Order Cart</h1>
- <table border="1">
- <thead>
- <td>
- Order Items
- </td>
- <td>
- No. Item
- </td>
- <td>
- Subtotal
- </td>
- <td>
- </thead>
- </td>
- <% Connection connection = null;
- try {
- Class.forName("org.gjt.mm.mysql.Driver");
- String url = "jdbc:mysql://localhost/dbburgenator";
- String user = "root";
- String pwd = "";
- connection = DriverManager.getConnection(url, user, pwd);
- Statement statement = null;
- ResultSet resultSet = null;
- statement = connection.createStatement();
- String sql = "select * from product";
- resultSet = statement.executeQuery(sql);
- while (resultSet.next()) {
- //start one product
- if ((order1.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order1")) != null) && (((String) session.getAttribute("qty1")) != null)) {
- %>
- <tr>
- <td>
- <%=resultSet.getString("productName")%>
- </td>
- <td>
- <form name="orderCart" action="updateCart.jsp" method="POST">
- <input type='text' name='qty1' id='qty1' value="<%=qty1%>" size="1" />
- <input type='button' name='add' onclick='javascript: document.getElementById("qty1").value++;' value='+'/>
- <input type='button' name='subtract' onclick='javascript: document.getElementById("qty1").value--;' value='-'/>
- </td>
- <td>
- <%
- int Iqty = Integer.parseInt(qty1);
- double price = resultSet.getDouble("productPrice");
- subtotal1 = 0.0;
- subtotal1 = Iqty * price;
- out.println("RM" + subtotal1);
- %>
- </td>
- <td>
- <input type="hidden" name="order1" value="<%=order1%>">
- <input type="submit" value="Update Order">
- </form>
- </td>
- </tr>
- <%
- }
- //end one product
- //start one product
- if ((order2.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order2")) != null) && (((String) session.getAttribute("qty2")) != null)) {
- %>
- <tr>
- <td>
- <%=resultSet.getString("productName")%>
- </td>
- <td>
- <form name="orderCart" action="updateCart.jsp" method="POST">
- <input type='text' name='qty2' id='qty2' value="<%=qty2%>" size="1" />
- <input type='button' name='add' onclick='javascript: document.getElementById("qty2").value++;' value='+'/>
- <input type='button' name='subtract' onclick='javascript: document.getElementById("qty2").value--;' value='-'/>
- </td>
- <td>
- <%
- int Iqty = Integer.parseInt(qty2);
- double price = resultSet.getDouble("productPrice");
- subtotal2 = 0.0;
- subtotal2 = Iqty * price;
- out.println("RM" + subtotal2);
- %>
- </td>
- <td>
- <input type="hidden" name="order2" value="<%=order2%>">
- <input type="submit" value="Update Order">
- </form>
- </td>
- </tr>
- <%
- }
- //end one product
- //start one product
- if ((order3.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order3")) != null) && (((String) session.getAttribute("qty3")) != null)) {
- %>
- <tr>
- <td>
- <%=resultSet.getString("productName")%>
- </td>
- <td>
- <form name="orderCart" action="updateCart.jsp" method="POST">
- <input type='text' name='qty3' id='qty3' value="<%=qty3%>" size="1" />
- <input type='button' name='add' onclick='javascript: document.getElementById("qty3").value++;' value='+'/>
- <input type='button' name='subtract' onclick='javascript: document.getElementById("qty3").value--;' value='-'/>
- </td>
- <td>
- <%
- int Iqty = Integer.parseInt(qty3);
- double price = resultSet.getDouble("productPrice");
- subtotal3 = 0.0;
- subtotal3 = Iqty * price;
- out.println("RM" + subtotal3);
- %>
- </td>
- <td>
- <input type="hidden" name="order3" value="<%=order3%>">
- <input type="submit" value="Update Order">
- </form>
- </td>
- </tr>
- <%
- }
- //end one product
- //start one product
- if ((order4.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order4")) != null) && (((String) session.getAttribute("qty4")) != null)) {
- %>
- <tr>
- <td>
- <%=resultSet.getString("productName")%>
- </td>
- <td>
- <form name="orderCart" action="updateCart.jsp" method="POST">
- <input type='text' name='qty4' id='qty4' value="<%=qty4%>" size="1" />
- <input type='button' name='add' onclick='javascript: document.getElementById("qty4").value++;' value='+'/>
- <input type='button' name='subtract' onclick='javascript: document.getElementById("qty4").value--;' value='-'/>
- </td>
- <td>
- <%
- int Iqty = Integer.parseInt(qty4);
- double price = resultSet.getDouble("productPrice");
- subtotal4 = 0.0;
- subtotal4 = Iqty * price;
- out.println("RM" + subtotal4);
- %>
- </td>
- <td>
- <input type="hidden" name="order4" value="<%=order4%>">
- <input type="submit" value="Update Order">
- </form>
- </td>
- </tr>
- <%
- }
- //end one product
- //start one product
- if ((order5.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order5")) != null) && (((String) session.getAttribute("qty5")) != null)) {
- %>
- <tr>
- <td>
- <%=resultSet.getString("productName")%>
- </td>
- <td>
- <form name="orderCart" action="updateCart.jsp" method="POST">
- <input type='text' name='qty5' id='qty5' value="<%=qty5%>" size="1" />
- <input type='button' name='add' onclick='javascript: document.getElementById("qty5").value++;' value='+'/>
- <input type='button' name='subtract' onclick='javascript: document.getElementById("qty5").value--;' value='-'/>
- </td>
- <td>
- <%
- int Iqty = Integer.parseInt(qty5);
- double price = resultSet.getDouble("productPrice");
- subtotal5 = 0.0;
- subtotal5 = Iqty * price;
- out.println("RM" + subtotal5);
- %>
- </td>
- <td>
- <input type="hidden" name="order5" value="<%=order5%>">
- <input type="submit" value="Update Order">
- </form>
- </td>
- </tr>
- <%
- }
- //end one product
- //start one product
- if ((order6.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order6")) != null) && (((String) session.getAttribute("qty6")) != null)) {
- %>
- <tr>
- <td>
- <%=resultSet.getString("productName")%>
- </td>
- <td>
- <form name="orderCart" action="updateCart.jsp" method="POST">
- <input type='text' name='qty6' id='qty6' value="<%=qty6%>" size="1" />
- <input type='button' name='add' onclick='javascript: document.getElementById("qty6").value++;' value='+'/>
- <input type='button' name='subtract' onclick='javascript: document.getElementById("qty6").value--;' value='-'/>
- </td>
- <td>
- <%
- int Iqty = Integer.parseInt(qty6);
- double price = resultSet.getDouble("productPrice");
- subtotal6 = 0.0;
- subtotal6 = Iqty * price;
- out.println("RM" + subtotal6);
- %>
- </td>
- <td>
- <input type="hidden" name="order6" value="<%=order6%>">
- <input type="submit" value="Update Order">
- </form>
- </td>
- </tr>
- <%
- }
- //end one product
- //start one product
- if ((order7.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order7")) != null) && (((String) session.getAttribute("qty7")) != null)) {
- %>
- <tr>
- <td>
- <%=resultSet.getString("productName")%>
- </td>
- <td>
- <form name="orderCart" action="updateCart.jsp" method="POST">
- <input type='text' name='qty7' id='qty7' value="<%=qty7%>" size="1" />
- <input type='button' name='add' onclick='javascript: document.getElementById("qty7").value++;' value='+'/>
- <input type='button' name='subtract' onclick='javascript: document.getElementById("qty7").value--;' value='-'/>
- </td>
- <td>
- <%
- int Iqty = Integer.parseInt(qty7);
- double price = resultSet.getDouble("productPrice");
- subtotal7 = 0.0;
- subtotal7 = Iqty * price;
- out.println("RM" + subtotal7);
- %>
- </td>
- <td>
- <input type="hidden" name="order7" value="<%=order7%>">
- <input type="submit" value="Update Order">
- </form>
- </td>
- </tr>
- <%
- }
- //end one product
- //start one product
- if ((order8.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order8")) != null) && (((String) session.getAttribute("qty8")) != null)) {
- %>
- <tr>
- <td>
- <%=resultSet.getString("productName")%>
- </td>
- <td>
- <form name="orderCart" action="updateCart.jsp" method="POST">
- <input type='text' name='qty8' id='qty8' value="<%=qty8%>" size="1" />
- <input type='button' name='add' onclick='javascript: document.getElementById("qty8").value++;' value='+'/>
- <input type='button' name='subtract' onclick='javascript: document.getElementById("qty8").value--;' value='-'/>
- </td>
- <td>
- <%
- int Iqty = Integer.parseInt(qty8);
- double price = resultSet.getDouble("productPrice");
- subtotal8 = 0.0;
- subtotal8 = Iqty * price;
- out.println("RM" + subtotal8);
- %>
- </td>
- <td>
- <input type="hidden" name="order8" value="<%=order8%>">
- <input type="submit" value="Update Order">
- </form>
- </td>
- </tr>
- <%
- }
- //end one product
- //start one product
- if ((order9.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order9")) != null) && (((String) session.getAttribute("qty9")) != null)) {
- %>
- <tr>
- <td>
- <%=resultSet.getString("productName")%>
- </td>
- <td>
- <form name="orderCart" action="updateCart.jsp" method="POST">
- <input type='text' name='qty9' id='qty9' value="<%=qty9%>" size="1" />
- <input type='button' name='add' onclick='javascript: document.getElementById("qty9").value++;' value='+'/>
- <input type='button' name='subtract' onclick='javascript: document.getElementById("qty9").value--;' value='-'/>
- </td>
- <td>
- <%
- int Iqty = Integer.parseInt(qty9);
- double price = resultSet.getDouble("productPrice");
- subtotal9 = 0.0;
- subtotal9 = Iqty * price;
- out.println("RM" + subtotal9);
- %>
- </td>
- <td>
- <input type="hidden" name="order9" value="<%=order9%>">
- <input type="submit" value="Update Order">
- </form>
- </td>
- </tr>
- <%
- }
- //end one product
- //start one product
- if ((order10.equals(resultSet.getString("productID"))) && (((String) session.getAttribute("order10")) != null) && (((String) session.getAttribute("qty10")) != null)) {
- %>
- <tr>
- <td>
- <%=resultSet.getString("productName")%>
- </td>
- <td>
- <form name="orderCart" action="updateCart.jsp" method="POST">
- <input type='text' name='qty10' id='qty10' value="<%=qty10%>" size="1" />
- <input type='button' name='add' onclick='javascript: document.getElementById("qty10").value++;' value='+'/>
- <input type='button' name='subtract' onclick='javascript: document.getElementById("qty10").value--;' value='-'/>
- </td>
- <td>
- <%
- int Iqty = Integer.parseInt(qty10);
- double price = resultSet.getDouble("productPrice");
- subtotal10 = 0.0;
- subtotal10 = Iqty * price;
- out.println("RM" + subtotal10);
- %>
- </td>
- <td>
- <input type="hidden" name="order10" value="<%=order10%>">
- <input type="submit" value="Update Order">
- </form>
- </td>
- </tr>
- <%
- }
- //end one product
- }
- connection.close();
- } catch (Exception e) {
- out.println(e);
- }
- %>
- <tr>
- <td colspan="2" border="0">
- <%out.println("<center>TOTAL :</center>");%>
- </td>
- <td colspan="2" border="0">
- <%
- if ((((String) session.getAttribute("qty1")) != null) && (((String) session.getAttribute("qty2")) != null)) {
- int Iqty = Integer.parseInt(qty1);
- int Iqty2 = Integer.parseInt(qty2);
- }
- double total = 0.0;
- total = subtotal1 + subtotal2 + subtotal3 + subtotal4 + subtotal5 + subtotal6 + subtotal7 + subtotal8 + subtotal9 + subtotal10;
- out.println("<center>RM" + total + "</center>");
- %>
- </td>
- </tr>
- </table>
- </form>
- <p></p>
- <form action="payment.jsp">
- <input type="submit" value="Confirm Order" />
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement