<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>

<%@page import="java.sql.*" %>    

<%


if(request.getParameter("submit") != null){
	
	String employeename = request.getParameter("employeename");
	String employeedepartment = request.getParameter("employeedepartment");
	String employeecompany = request.getParameter("employeecompany");
	
	Connection con;
	PreparedStatement pst;
	ResultSet rs;
	
	Class.forName("com.mysql.jdbc.Driver");
	con = DriverManager.getConnection("jdbc:mysql://localhost:3306/codespeedy","root","sqlsewebsite@2");
	
	pst = con.prepareStatement("insert into employee(employeename,employeedepartment,employeecompany)values(?,?,?)");
	
	pst.setString(1, employeename);
	pst.setString(2, employeedepartment);
	pst.setString(3, employeecompany);
	pst.executeUpdate();
	
%>

<script>

alert("Record Added");

</script>
    
<%
}

%>    
   
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<link href="bootstrap/css/bootstrap.css" rel="stylesheet" type="text/css"/>
<link href="bootstrap/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<h1>Employee Portal</h1>
<br>
<div class="row">

<div class = "col-sm-4">  <!--FOR FORM CREATION-->

<form method = "post" action = "#">

<div align = "left">
<label class = "form-label">Employee Name</label>
<input type = "text" class="form-control" placeholder="Employee Name" name = "employeename" id = "employeename" required>
</div>
<div align = "left">
<label class = "form-label">Employee Department</label>
<input type = "text" class="form-control" placeholder="Employee Department" name = "employeedepartment" id = "employeedepartment" required>
</div>
<div align = "left">
<label class = "form-label">Employee Company</label>
<input type = "text" class="form-control" placeholder="Employee Company" name = "employeecompany" id = "employeecompany" required>
</div>
<br>
<div align = "right">
<input type = "submit" id = "submit" value = "submit" name = "submit" class = "btn btn-info">
<input type = "reset" id = "reset" value = "reset" name = "reset" class = "btn btn-warning">
</div>
</form>
</div>

<div class = "col-sm-8">  <!-- FOR TABLE CREATION -->
<div class = "panel-body">

<table id = "tbl-student" class = "table table-responsive table-bordered">
<thead>
<tr>
<th>Employee Name</th>
<th>Employee Department</th>
<th>Employee Company</th>
<th>Edit</th>
<th>delete</th>
</tr>

<%

Connection con;
PreparedStatement pst;
ResultSet rs;

Class.forName("com.mysql.jdbc.Driver");
con = DriverManager.getConnection("jdbc:mysql://localhost:3306/codespeedy","root","sqlsewebsite@2");

String sql = "select * from employee";
Statement st = con.createStatement();
rs = st.executeQuery(sql);

while(rs.next()){
	
	String id = rs.getString("id");
	


%>



<tr>
<td><%=rs.getString("employeename") %></td>
<td><%=rs.getString("employeedepartment") %></td>
<td><%=rs.getString("employeecompany") %></td>
<td><a href = "update.jsp?id=<%=id%>">Edit</a></td>
<td><a href = "delete.jsp?id=<%=id%>">Delete</a></td>

</tr>

<%
}
%>

</thead>



</table>


</div>

</div>
</div>

</body>
</html>