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


if(request.getParameter("submit") != null){
	
	String id = request.getParameter("id");
	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("update employee set employeename = ?,employeedepartment = ?, employeecompany = ? where id = ?");
	
	pst.setString(1, employeename);
	pst.setString(2, employeedepartment);
	pst.setString(3, employeecompany);
	pst.setString(4, id);
	pst.executeUpdate();
	
%>

<script>

alert("Record Updated Successfully");

</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>Update Employee Record</h1>

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

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

<%

Connection con;
PreparedStatement pst;
ResultSet rs;

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

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

pst = con.prepareStatement("select * from employee where id = ?");
pst.setString(1, id);
rs = pst.executeQuery();

while(rs.next()){
%>


<div align = "left">
<label class = "form-label">Employee Name</label>
<input type = "text" class="form-control" placeholder="Employee Name" value="<%=rs.getString("employeename")%>" 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" value="<%=rs.getString("employeedepartment")%>" 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" value="<%=rs.getString("employeecompany")%>" 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>
<br>
<div align = "right">
<p><a href = "index.jsp">Click to go back...</a></p>



</div>

</form>
</div>


</div>




</body>
</html>