ASP Tutorials
Insert Records into an Access Database
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Insert a Quote</title>
</head>
<body>
<form method="post" action="insert.asp">
first_name:<input type="text" name="first_name" id="first_name" /><br />
last_name:<input type="text" name="last_name" id="last_name" /><br />
quote:<textarea name="quote" id="quote" cols="45" rows="5"></textarea><br />
subject:<input type="text" name="subject" id="subject" /><br />
<input type="submit" value="Submit" />
</form>
</body>
</html>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!-- #include file = "data_source.inc" -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Insert a New Quote</title>
</head>
<body>
<%
Dim my_connection, my_query
Dim first_name, last_name, quote, subject
first_name = request.form("first_name")
last_name = request.form("last_name")
quote = request.form("quote")
subject = request.form("subject")
my_query = "INSERT INTO my_quotes (first_name, last_name, quote, subject) VALUES " & _
"('" & first_name & "', '" & last_name & "', '" & quote & "', '" & subject & "')"
Set my_connection = Server.CreateObject("ADODB.Connection")
my_connection.Open (my_database_source)
my_connection.Execute (my_query)
my_connection.Close
Set my_connection = Nothing
response.write "<div>Data has been inserted successfully!</div>"
%>
</body>
</html>
my_database_source = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("/db_dir/quotes.mdb")
%>