protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		conn = DatabaseConnection.getConnection();
		response.setContentType("text/html");
		String name = request.getParameter("name");
		String surname = request.getParameter("surname");
		String number = request.getParameter("number");
		String username = request.getParameter("userName");
		String email = request.getParameter("userEmail");
		String city = request.getParameter("location");
		String password ="";
		try {
			password = stringToHash(request.getParameter("userPassword"));
		} catch (NoSuchAlgorithmException e1) {
			e1.printStackTrace();
		}


		try {
			String query = "SELECT * FROM kasutajad WHERE kasutajanimi=?";
			PreparedStatement prepStmt2 = conn.prepareStatement(query);
			prepStmt2.setString(1, username);
			ResultSet rs = prepStmt2.executeQuery();

			if (rs.next()) {
				response(response, "Selline kasutaja on juba olemas");
			} else {
				try {
					int id=0;
					String query3 = "SELECT * FROM kasutajad";
					PreparedStatement prepStmt3 = conn.prepareStatement(query3);
					ResultSet rs2 = prepStmt3.executeQuery();
					
					while (rs2.next()) {
						id=id+1;
					}
					String query2 = "INSERT INTO kasutajad VALUES(default,?,?,?,?,?,?,?,?)";
					PreparedStatement prepStmt = conn.prepareStatement(query2);
					prepStmt.setString(1, name);
					prepStmt.setString(2, surname);
					prepStmt.setString(3, username);
					prepStmt.setString(4, password);
					prepStmt.setString(5, city);
					prepStmt.setString(6, email);
					prepStmt.setString(7, number);
					prepStmt.setBoolean(8, true);
					prepStmt.executeUpdate();
					response(response, "Kasutaja edukalt sisestatud andmebaasi");
				} catch (Exception e) {
					response(response, "Midagi läks pekki");
				}
			}

		} catch (SQLException e) {
			response(response, "SQL EXCEPTION");

		} catch (Exception e) {
			response(response, "Midagi läks pekki");
		}

	}