<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1" import="java.sql.*"%>
<%
	Connection conn = null;
	PreparedStatement stmt = null;
	try
	{
		Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
		conn = DriverManager.getConnection("jdbc:odbc:Presidents");
		
		String field = request.getParameter("field");
		String value = request.getParameter("value").replaceAll("'","''");
		String presID = request.getParameter("pid");
		String sql = "UPDATE Presidents SET " + field + " = ? WHERE PresidentID = ?";
		
		stmt = conn.prepareStatement(sql);
		stmt.setString(1, value);
		stmt.setString(2, presID);
		
		stmt.executeUpdate();
		out.write("success");
	}
	catch (Exception e)
	{
		out.write("Failed:\n\n " + e.toString());
	}
	finally 
	{
		if (stmt != null) stmt.close();
		if (conn != null) conn.close();
	}
%>