Click here to Skip to main content
15,879,535 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<%@page import="Project.ConnectionProvider"%>
<%@page import="java.sql.*"%>
<%
String email=session.getAttribute("email").toString();
String address=request.getParameter("address");
String city=request.getParameter("city");
String state=request.getParameter("state");
String country=request.getParameter("country");
String mobileNumber=request.getParameter("mobileNumber");
String paymentMethod=request.getParameter("paymentMethod");
String transactionId="";
transactionId=request.getParameter("transactionId");
String status="bill";
try
{
	Connection con=ConnectionProvider.getCon();
	PreparedStatement ps=con.prepareStatement("update users set address=?,city=?,state=?,country=?,mobileNumber=?");
	ps.setString(1, address);
	ps.setString(2, city);
	ps.setString(3, state);
	ps.setString(4, country);
	ps.setString(5, mobileNumber);
	ps.setString(6, email);
	ps.executeUpdate();
	
	PreparedStatement ps2=con.prepareStatement("update cart set address=?,city=?,state=?,country=?,mobileNumber=?,orderDate=now(),deliveryDate=DATE_ADD(orderDate,INTERVAL 7 DAY),paymentMethod=?,transactionId=?,status=? where email=? and address is NULL");
	ps2.setString(1, address);
	ps2.setString(2, city);
	ps2.setString(3, state);
	ps2.setString(4, country);
	ps2.setString(5, mobileNumber);
	ps2.setString(6, paymentMethod);
	ps2.setString(7, transactionId);
	ps2.setString(8, status);
	ps2.setString(9, email);
	ps2.executeUpdate();
	response.sendRedirect("bill.jsp");
}
catch(Exception e)
{
System.out.println(e);	
}
%>


What I have tried:

This is my first project as a student and I have no experience in coding and I am following a youtube Tutorial to create an online shopping project and I am having a problem with this particular code the tutorial I am following has the same code I've checked multiple times but I couldn't find any syntax error help me out with this if you can
Posted
Updated 7-Aug-21 3:22am

The problem - the major problem, they generally have many - with youtube "tutorial videos" is that they are there for monetization: they want your views, your subscriptions. They don't care about the quality, or how you get on. The money is all. And as a result, the person making the video normally has no idea how to make a video, or how to teach, or (in most cases) any more idea of how to code than you do. Often less.

So if the code doesn't work - and it won't - your best recourse is to do two things:
1) Comment loudly to the video to that effect, and downvote it.
2) Go elsewhere and never touch his videos again.

The chances are you won't get a reply - why would you? Your "view" has paid him already - because they have no interest in the code or idea how to fix it.
But you might dissuade others from the same problem ...

That code isn't worth fixing: if that doesn't work you have to ask yourself "why not?" And "what is the chance that that's the only fault in the code?"

Get a book; go on a course. You will learn more, from people who know what they are talking about and can pass the information on in a structured manner.
 
Share this answer
 
Quote:
I've checked multiple times but I couldn't find any syntax error

You are not told there is a syntax error, you are told there is a logical error !
Quote:
Parameter index out of range (6 > number of parameters, which is 5).

This means that your code is wrong :
Java
Connection con=ConnectionProvider.getCon();
PreparedStatement ps=con.prepareStatement("update users set address=?,city=?,state=?,country=?,mobileNumber=?");
ps.setString(1, address);
ps.setString(2, city);
ps.setString(3, state);
ps.setString(4, country);
ps.setString(5, mobileNumber);
ps.setString(6, email); // Where is email in the query ?
ps.executeUpdate();
 
Share this answer
 
Comments
Dave Kreskowiak 7-Aug-21 11:34am    
Better yet, where is the WHERE clause in the UPDATE statement?
Patrice T 7-Aug-21 11:53am    
The update is for all reccords. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900