//HTML Page for Signup form
<%--
Document : signup
Created on : Feb 11, 2016, 11:33:09 AM
Author : Ak-47
--%>
<!DOCTYPE html>
<html>
<head>
<title>signup</title>
<meta charset="utf-8">
<script>
function myFunction() // function to check passsword and confirm password
{
var a,b;
a=document.form1.pass.value;
b=document.form1.passw.value;
if(a!=b || a=="")
{
alert("Password doesnt match");
form1.action = 'http://www.google.com/';
}
else
{
form1.action='insertuser.jsp';
}
}
</script>
</head>
<body>
<form name="form1" onsubmit="myFunction()" action="insertuser.jsp" method="post">
<label>First Name: </label>
<input type="text" name="fname" placeholder="Enter First Name" required>
<label>Last Name: </label>
<input type="text" name="lname" placeholder="Enter Last Name" required>
<label>Email:</label>
<input type="email" name="email" placeholder="Enter email" required>
<label>Mobile:</label>
<input type="text" name="mobile" placeholder="Enter Cellular Number" required>
<label>Password:</label>
<input type="password" name="pass" placeholder="Enter password" required>
<label>Confirm Password:</label>
<input type="password" name="passw" placeholder="Enter password again" required>
<label>Date of Birth:</label>
<input type="date" name="dob">
<label>Gender:</label>
<select name="gender">
<option value="Male">Male</option>
<option value="Female">Female</option>
<option value="Transgender">Transgender</option>
</select>
<label>Address:</label>
<textarea rows="5" name="address" required></textarea>
<button type="submit" class="btn btn-default">Submit</button>
</form>
</body>
</html>
<%--
Document : insertuser
Created on : Feb 11, 2016, 1:53:30 PM
Author : Ak-47
--%>
<%@ page import="java.io.*,java.util.*, javax.servlet.*, java.sql.*, databasecon.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%
//declaring all the variables
String fname=request.getParameter("fname");
String lname=request.getParameter("lname");
String userid=request.getParameter("email");
String pass=request.getParameter("pass");
String mobile=request.getParameter("mobile");
String dob=request.getParameter("dob");
String gender=request.getParameter("gender");
String address=request.getParameter("address");
String filePath="C:/proj/zot/web/user";
// declaring the file path where we want to create user folder and upload data later.
try
{
File root = new File(filePath);
File newfolder = new File(root, "/"+userid); //creating the new folder
newfolder.mkdir();
filePath=filePath+"/"+userid+"/";
File newfldr = new File(filePath, "gallery");
newfldr.mkdir();
File newfoldr = new File(filePath, "products");
newfoldr.mkdir();
Connection con=null;
Statement st=null;
String sql="insert into users values ('"+userid+"','"+pass+"','"+fname+"','"+lname+"','"+dob+"','"+gender+"','"+mobile+"','"+address+"')";
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con=DriverManager.getconnection("jdbc:odbc:DB_Name"); //these drivers are only for ms-access.
st=con.createStatement();
int x=st.executeUpdate(sql);
if(x!=0)
{
out.println("created successfully : <h2>"+userid+" : "+mobile+"</h2><br>");
out.println("for more details Contact us. <br>");
}
else
{
out.println( userid + " already exists");
}
st.close();
con.close();
}
catch(SQLException e)
{
out.println(userid +" Already exists "+e);
}
%>
</body>
</html>