I am trying to create a registration form in Bootstrap and then connecting it to the Oracle Database but the data entered by the user isn't sending any value to the database. Please suggest what editing I should do.

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Home - Student Registration Form</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/datepicker.css" rel="stylesheet">
    <style>
      .error{
        color: red;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="row">
        <form id="regform" class="form-horizontal" method="post" action="">
          <fieldset>
          <!-- Form Name -->
          <legend>Student Registration</legend>
          <!-- Text input-->
          <div class="form-group">
            <label class="col-md-4 control-label" for="firstname">First Name</label>
            <div class="col-md-4">
            <input id="firstname" name="firstname" type="text" placeholder="First Name" class="form-control input-md">
            </div>
          </div>
          <!-- Text input-->
          <div class="form-group">
            <label class="col-md-4 control-label" for="lastname">Last Name</label>
            <div class="col-md-4">
            <input id="lastname" name="lastname" type="text" placeholder="Last Name" class="form-control input-md">
            </div>
          </div>
          <!-- Text input-->
          <div class="form-group">
            <label class="col-md-4 control-label" for="dob">Date of birth</label>
            <div class="col-md-4">
            <input id="dob" name="dob" type="text" placeholder="Date of birth" class="form-control input-md">
            </div>
          </div>
          <!-- Text input-->
          <div class="form-group">
            <label class="col-md-4 control-label" for="age">Age</label>
            <div class="col-md-4">
            <input id="age" name="age" type="text" placeholder="Age" class="form-control input-md" disabled>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-4 control-label" for="sex">Sex</label>
            <div class="col-md-4">
               <label class="radio-inline"><input type="radio" name="Sex">Male</label>
                     <label class="radio-inline"><input type="radio" name="Sex">Female</label>
            </div>
          </div>
          <!-- Select Basic -->
          <div class="form-group">
            <label class="col-md-4 control-label" for="subjects">Subjects</label>
            <div class="col-md-4">
              <select id="subjects" name="subjects" class="form-control">
                <option value="1">Database</option>
                <option value="2">ADA</option>
                <option value="3">Networking</option>
              </select>
            </div>
          </div>
          <!-- Textarea -->
          <div class="form-group">
            <label class="col-md-4 control-label" for="localaddress">Local Address</label>
            <div class="col-md-4">
              <textarea class="form-control" id="localaddress" name="localaddress"></textarea>
            </div>
          </div>
          <!-- Multiple Checkboxes (inline) -->
          <div class="form-group">
            <label class="col-md-4 control-label" for="localaddresscheckbox">Permenant address</label>
            <div class="col-md-4">
              <label class="checkbox-inline" for="localaddresscheckbox">
                <input type="checkbox" name="localaddresscheckbox" id="localaddresscheckbox" value="1">
                Copy Local Address to permanent Address
              </label>
            </div>
          </div>
          <!-- Textarea -->
          <div class="form-group">
            <label class="col-md-4 control-label" for="permenantaddress">Permenant Address</label>
            <div class="col-md-4">
              <textarea class="form-control" id="permenantaddress" name="permenantaddress"></textarea>
            </div>
          </div>
          <!-- Button -->
          <div class="form-group">
            <label class="col-md-4 control-label" for="submit"></label>
            <div class="col-md-4">
              <button id="submit" name="submit" class="btn btn-primary">Submit</button>
            </div>
          </div>
        </fieldset>
        </form>
      </div>
    </div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
    <script src="js/bootstrap-datepicker.js"></script>
    <script src="js/jquery.validate.min.js"></script>
    <script>
      (function() {

        jQuery.validator.addMethod("lettersonly", function(value, element) {
          return this.optional(element) || /^[a-z]+$/i.test(value);
        }, "Letters only please");

        $("#regform").validate({
          rules: {
            dob: "required",
            localaddress: "required",
            permenantaddress: "required",
            firstname: {
                lettersonly: true,
                required: true
            },
            lastname: {
                lettersonly: true,
                required: true
            }
          },
          submitHandler: function(form) {
            form.submit();
          }
        });

        //init datepicker
        $('#dob').datepicker({
            'format': 'yyyy-mm-dd',
            'autoclose': true
        });

        //copy localaddress to permenant address on checkbox click
        $('#localaddresscheckbox').click(function(){
          if($(this).is(':checked')) {
            var localaddress = $('#localaddress').val();
            $('#permenantaddress').val(localaddress); //copy local address to permenant address box
          }
          else {
            $('#permenantaddress').val('');
          }
        });

        //age handler
        $('#dob').datepicker().on('changeDate', function (ev) {
          //get current date
          var today = new Date();
          var currentYear = today.getFullYear(); //current year
          var selectedYear = $(this).val().split('-')[0]; //selected dob year
          var age = Number(currentYear) - Number(selectedYear);
          $('#age').val(age);
        });

      })();
    </script>
  </body>
</html>

The above only shows your form and some validation. Where is your server side script which connects to your database?

commented: can you please look at the server-side code +0

I edited the code. But now the copy from the local to permanent address has stopped working.

The code is as follows:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Home - Student Registration Form</title>
    <link href="css/bootstrap.min.css" rel="stylesheet">
    <link href="css/datepicker.css" rel="stylesheet">
    <style>
      .error{
        color: red;
      }
    </style>
  </head>
  <body>
    <div class="container">
      <div class="row">
        <form id="regform" class="form-horizontal" action="NewFile.jsp">
          <fieldset>
          <!-- Form Name -->
          <legend>Student Registration</legend>
          <!-- Text input-->
          <div class="form-group">
            <label class="col-md-4 control-label" for="firstname">First Name</label>
            <div class="col-md-4">
            <input id="firstname" name="firstname" type="text" placeholder="First Name" class="form-control input-md">
            </div>
          </div>
          <!-- Text input-->
          <div class="form-group">
            <label class="col-md-4 control-label" for="lastname">Last Name</label>
            <div class="col-md-4">
            <input id="lastname" name="lastname" type="text" placeholder="Last Name" class="form-control input-md">
            </div>
          </div>
          <!-- Text input-->
          <div class="form-group">
            <label class="col-md-4 control-label" for="dob">Date of birth</label>
            <div class="col-md-4">
            <input id="dob" name="dob" type="text" placeholder="Date of birth" class="form-control input-md">
            </div>
          </div>
          <!-- Text input-->
          <div class="form-group">
            <label class="col-md-4 control-label" for="age">Age</label>
            <div class="col-md-4">
            <input id="age" name="age" type="text" placeholder="Age" class="form-control input-md" disabled>
            </div>
          </div>
          <div class="form-group">
            <label class="col-md-4 control-label" for="sex">Sex</label>
            <div class="col-md-4">
              <label class="radio-inline"><input type="radio" name="sex" value="Male">Male</label>
              <label class="radio-inline"><input type="radio" name="sex" value="Female">Female</label>
            </div>
          </div>
          <!-- Select Basic -->
          <div class="form-group">
            <label class="col-md-4 control-label" for="subjects">Subjects</label>
            <div class="col-md-4">
              <select id="subjects" name="subjects" class="form-control">
                <option value="Database">Database</option>
                <option value="ADA">ADA</option>
                <option value="Networking">Networking</option>
              </select>
            </div>
          </div>
          <!-- Textarea -->
          <div class="form-group">
            <label class="col-md-4 control-label" for="localaddress">Local Address</label>
            <div class="col-md-4">
              <textarea class="form-control" id="localaddress" name="localaddress"></textarea>
            </div>
          </div>
          <!-- Multiple Checkboxes (inline) -->
          <div class="form-group">
            <label class="col-md-4 control-label" for="localaddresscheckbox">Permenant address</label>
            <div class="col-md-4">
              <label class="checkbox-inline" for="localaddresscheckbox">
                <input type="checkbox" name="localaddresscheckbox" id="localaddresscheckbox" value="1">
                Copy Local Address to permanent Address
              </label>
            </div>
          </div>
          <!-- Textarea -->
          <div class="form-group">
            <label class="col-md-4 control-label" for="permanentaddress">Permanent Address</label>
            <div class="col-md-4">
              <textarea class="form-control" id="permanentaddress" name="permanentaddress"></textarea>
            </div>
          </div>
          <!-- Button -->
          <div class="form-group">
            <label class="col-md-4 control-label" for="submit"></label>
            <div class="col-md-4">
              <button id="submit" name="submit" class="btn btn-primary">Submit</button>
            </div>
          </div>
        </fieldset>
        </form>
      </div>
    </div>
    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="js/bootstrap.min.js"></script>
    <script src="js/bootstrap-datepicker.js"></script>
    <script src="js/jquery.validate.min.js"></script>
    <script>
      (function() {

        jQuery.validator.addMethod("lettersonly", function(value, element) {
          return this.optional(element) || /^[a-z]+$/i.test(value);
        }, "Letters only please");

        $("#regform").validate({
          rules: {
            dob: "required",
            localaddress: "required",
            permenantaddress: "required",
            firstname: {
                lettersonly: true,
                required: true
            },
            lastname: {
                lettersonly: true,
                required: true
            }
          },
          submitHandler: function(form) {
            form.submit();
          }
        });

        //init datepicker
        $('#dob').datepicker({
            'format': 'yyyy-mm-dd',
            'autoclose': true
        });

        //copy localaddress to permenant address on checkbox click
        $('#localaddresscheckbox').click(function(){
          if($(this).is(':checked')) {
            var localaddress = $('#localaddress').val();
            $('#permenantaddress').val(localaddress); //copy local address to permenant address box
          }
          else {
            $('#permenantaddress').val('');
          }
        });

        //age handler
        $('#dob').datepicker().on('changeDate', function (ev) {
          //get current date
          var today = new Date();
          var currentYear = today.getFullYear(); //current year
          var selectedYear = $(this).val().split('-')[0]; //selected dob year
          var age = Number(currentYear) - Number(selectedYear);
          $('#age').val(age);
        });

      })();
    </script>
  </body>
</html>

The server side code is as follows:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@page import="java.sql.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String firstname=request.getParameter("firstname");
System.out.println("First name="+firstname);
String lastname=request.getParameter("lastname");
System.out.println("Last name="+lastname);
String dob=request.getParameter("dob");
System.out.println("Date of Birth="+dob);
String age=request.getParameter("age");
System.out.println("Age="+age);
String sex=request.getParameter("sex");
System.out.println("Sex="+sex);
String subjects=request.getParameter("subjects");
System.out.println("Subject="+subjects);
String localaddresscheckbox=request.getParameter("localaddresscheckbox");
System.out.println("Local Address="+localaddresscheckbox);
String permanentaddress=request.getParameter("permanentaddress");
System.out.println("Permanent Address="+permanentaddress);

try
{
//System.out.println(0);
//Class.forName("oracle.jdbc.driver.OracleDriver");

Class.forName("oracle.jdbc.driver.OracleDriver");
System.out.println(1);
Connection con=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","Subhankar","oracle07");  
System.out.println(2);

Statement st= con.createStatement();
//String sql = "INSERT INTO STUDENT_DETAILS VALUES (firstname,lastname,dob,age,sex,subjects,localaddresscheckbox,permanentaddress)";

String sql="INSERT INTO STUDENT_DETAILS (first_name,last_name,date_of_birth,age,sex,subject,local_address,permanent_address) VALUES ('"+firstname+"','"+lastname+"','"+dob+"','"+age+"','"+sex+"','"+subjects+"','"+localaddresscheckbox+"','"+permanentaddress+"')";
st.executeUpdate(sql);


//
//ResultSet rs=st.executeQuery("select * from studentdetails where studentid="+studentId);

}catch(Exception e)
{
    e.printStackTrace();
}

%>
</body>
</html>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.