Ye Htut

Ye Htut

  • NA
  • 120
  • 33.5k

insert data to DB with MS SQL using Classic ASP

May 5 2014 1:09 AM
first I made "connection.asp"
the codes in "connection.asp" file are as follows

<%
Dim conn
Set conn = Server.CreateObject("ADODB.Connection")
conn.Open "Provider=SQLOLEDB; Data Source = (local); Initial Catalog = Test; User Id = sa; Password=as"
If conn.errors.count = 0 Then
Response.Write "Connected OK"
End If
%>


then I made "author.asp". The following code are in "author.asp"

<!DOCTYPE html>
<!--#include file="connection.asp" -->
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="author.asp">
<label>AuthorID</label>
<input type="text" name="aid"><br>
<label>Author Name</label>
<input type="text" name="aname"><br>
<input type="submit" value="Register">
</form>

<%
dim aid,aname,objs
aid=Request.form("aid")
aname=Request.form("aname")
Set objdb=conn()
query = "INSERT INTO author (aid,aname) VALUES ('"& aid &"','"& aname &"')"
Set objs = objdb.Execute(query)
Response.Redirect ("thankyou.asp")
%>
</body>
</html>

the code can't run. I think, there may be error in "author.asp". So, Plz help me

Answers (1)