Hi All,
I am ASP beginner and seeking some help please. I am using online tutorial to learn. However been having this problem last 2 days. If I get any help, would be greatly appreciated to learner like me. I have 3 files listed codes for them below. I am creating basic addressbook which reads input from first file (addressbook_form.htm). I am using 2nd file (add_to_addressbook.asp) to post read-in data to 3rd file which is (addressbook.asp). I have gone thru each and every line of code but cannot get 'updated' addressbook.asp to work and show new entry being added. Again, any help be very helpful. please tell me what am i doing wrong here?
================================================== ===
addressbook_form.htm
<html>
<head>
<title>Adddressbook Form</title>
</head>
<body bgcolor="white" text="black">
<!-- Begin form code -->
<form name="form" method="post" action="add_to_addressbook.asp">
First Name: <input type="text" name="firstname" maxlength="20">
<br>
Last Name: <input type="text" name="lastname" maxlength="20">
<br>
Address: <input type="text" name="address" maxlength="20">
<br>
City: <input type="text" name="city" maxlength="20">
<br>
State: <input type="text" name="state" maxlength="20">
<br>
Zip: <input type="text" name="zip" maxlength="20">
<br>
Country: <input type="text" name="country" maxlength="20">
<br>
Email: <input type="text" name="email" maxlength="20">
<br>
Home Phone: <input type="text" name="homephone" maxlength="20">
<br>
Work Phone: <input type="text" name="workphone" maxlength="20">
<br>
Mobile Phone: <input type="text" name="mobilephone" maxlength="20">
<br>
<input type="submit" name="Submit" value="Submit">
</form>
<!-- End form code -->
</body>
</html>
================================================== =====
add_to_addressbook.asp
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsAddComments 'Holds the recordset for the new record to be added to the database
Dim strSQL 'Holds the SQL query for the database
'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("addressbook.mdb")
'Create an ADO recordset object
Set rsAddComments = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT FirstName, LastName, Address, City, State, Zip, Country, Email, HomePhone, WorkPhone, MobilePhone FROM addressbook;"
'Set the cursor type we are using so we can navigate through the recordset
rsAddComments.CursorType = 2
'Set the lock type so that the record is locked by ADO when it is updated
rsAddComments.LockType = 3
'Open the addressbook table using the SQL query held in the strSQL varaiable
rsAddComments.Open strSQL, adoCon
'Tell the recordset we are adding a new record to it
rsAddComments.AddNew
'Add a new record to the recordset
rsAddComments.Fields("FirstName") = Request.Form("firstname")
rsAddComments.Fields("LastName") = Request.Form("lastname")
rsAddComments.Fields("Address") = Request.Form("address")
rsAddComments.Fields("City") = Request.Form("city")
rsAddComments.Fields("State") = Request.Form("state")
rsAddComments.Fields("Zip") = Request.Form("zip")
rsAddComments.Fields("Country") = Request.Form("country")
rsAddComments.Fields("Email") = Request.Form("email")
rsAddComments.Fields("HomePhone") = Request.Form("homephone")
rsAddComments.Fields("WorkPhone") = Request.Form("workphone")
rsAddComments.Fields("MobilePhone") = Request.Form("mobilephone")
'Write the updated recordset to the database
rsAddComments.Update
'Reset server objects
rsAddComments.Close
Set rsAddComments = Nothing
Set adoCon = Nothing
'Redirect to the addressbook.asp page
Response.Redirect "addressbook.asp"
%>
================================================== ======
addressbook.asp
<html>
<head>
<title>Addressbook</title>
</head>
<body bgcolor="white" text="black">
<%
'Dimension variables
Dim adoCon 'Holds the Database Connection Object
Dim rsAddressbook 'Holds the recordset for the records in the database
Dim strSQL 'Holds the SQL query for the database
'Create an ADO connection odject
Set adoCon = Server.CreateObject("ADODB.Connection")
'Set an active connection to the Connection object using a DSN-less connection
adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("addressbook.mdb")
'Create an ADO recordset object
Set rsAddressbook = Server.CreateObject("ADODB.Recordset")
'Initialise the strSQL variable with an SQL statement to query the database
strSQL = "SELECT FirstName, LastName, Address, City, State, Zip, Country, Email, HomePhone, WorkPhone, MobilePhone FROM addressbook;"
'Open the recordset with the SQL query
rsAddressbook.Open strSQL, adoCon
'Loop through the recordset
Do While not rsAddressbook.EOF
'Write the HTML to display the current record in the recordset
Response.Write ("<br>")
Response.Write (rsAddressbook("FirstName"))
Response.Write ("<br>")
Response.Write (rsAddressbook("LastName"))
Response.Write ("<br>")
Response.Write (rsAddressbook("Address"))
Response.Write ("<br>")
Response.Write (rsAddressbook("City"))
Response.Write ("<br>")
Response.Write (rsAddressbook("State"))
Response.Write ("<br>")
Response.Write (rsAddressbook("Zip"))
Response.Write ("<br>")
Response.Write (rsAddressbook("Country"))
Response.Write ("<br>")
Response.Write (rsAddressbook("Email"))
Response.Write ("<br>")
Response.Write (rsAddressbook("HomePhone"))
Response.Write ("<br>")
Response.Write (rsAddressbook("WorkPhone"))
Response.Write ("<br>")
Response.Write (rsAddressbook("MobilePhone"))
Response.Write ("<br>")
'Move to the next record in the recordset
rsAddressbook.MoveNext
Loop
'Reset server objects
rsAddressbook.Close
Set rsAddressbook = Nothing
Set adoCon = Nothing
%>
</body>
</html>