<%@ page language = "java"%>
<%@ page import = "java.util.*"%>
<%@ page import = "java.sql.*"%>
<%@ page import = "java.io.*"%>
<%@ page import = "java.net.*"%>

<% 

String data = (request.getParameter("data")); 


System.out.println(request.getCharacterEncoding());
System.out.println(request.getContentLength());
System.out.println(request.getContentType());
System.out.println(request.getParameterNames());

//data= URLDecoder.decode(data,"UTF-8");


System.out.println(data);


int delimiter = data.indexOf("||");
int delimiter2 = data.indexOf("|||");


String name = data.substring(0,delimiter);
String band_id = data.substring(delimiter+2,delimiter2);
String post = data.substring(delimiter2+3);
/*
System.out.println((int)name.charAt(0));
System.out.println((int)'õ');
System.out.println('õ');
*/

post = post.replaceAll("\n","<br>");
System.out.println(name);
System.out.println(band_id);
System.out.println(post);


		Connection conn = null;  
           try
           {
               String userName = "root";
               String password = "";
               String url = "jdbc:mysql://localhost/band";
               Class.forName ("com.mysql.jdbc.Driver").newInstance();
               conn = DriverManager.getConnection (url, userName, password);
               System.out.println ("Database connection established");
               
               Statement s = conn.createStatement();
               
               
               
               
               int m;
               
               String insert_statement = ("insert into forumposts(name, post, band_id, date, time) VALUES ('"+name+"','"+post+"',"+band_id+",CURDATE(),CURTIME());");
               System.out.println(insert_statement);
               m = s.executeUpdate(insert_statement);
               
               if (m==1) out.println("Posted!");
               else out.println("NOT Posted!");
               
               
               
          }        
          
          
           catch (Exception e)
           {
               System.err.println ("database error");
               System.err.println (e);
               out.println("Error");
               return;
           }
           
           finally
           {
               if (conn != null)
               {
                   try
                   {
                       conn.close ();
                       System.out.println ("Database connection terminated");
                   }
                   catch (Exception e) { /* ignore close errors */ }
               }
           }
           
    


%>
