Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - web form entry to access database w/asp
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

web form entry to access database w/asp

 Post Reply Post Reply Page  123>
Author
swatson View Drop Down
Newbie
Newbie


Joined: 11 April 2003
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote swatson Quote  Post ReplyReply Direct Link To This Post Topic: web form entry to access database w/asp
    Posted: 11 April 2003 at 10:56am

Hi All:

I followed Bruce Corkhill's tutorials for connecting to and adding records to an access database using asp. My file for connecting to the database and displaying the records works.  But, my files for using a web form to enter records to the database do not.  I'm copying the files -- can you help identify the problem?  The web form connects to the access database but new record does not get added. Thanks for your help!

Stephanie Watson

web form file (form.html):

<html>
<head>
<title>Profile Data Entry Form</title>
</head>

<Body bgcolor="#0099CC" text="white" link="#0000FF" alink="#FF0000" vlink="#663399">
<font face = "Georgia">
<H1 Align="center">Profile Data Entry Form</H1>
</font>

<form name="Form" method="post" action="add_to_db.asp">

Facility_id
<input type = "text" name="Facility_id" size = 10>
<br>
Facility_name
<input type="text" name="Facility_name" size = 100>
<br>
Facility_description
<input type="text" name="Facility_description" size = 1000>
<br>
Street Address1
<input type="text" name="Street_address1" size = 100>
<br>
Street_Address2
<input type="text" name="Street_address2" size = 100>
City
<input type="text" name="City" size = 50>
State
<input type="text" name="State" size = 10>
<br>
Zipcode
<input type="text" name="Zipcode" size = 12>
<br>
Website
<input type="text" name="Website" size = 50>
<br>
Image
<input type="text" name="Image" size = 50>
<br>

<p><input type="Submit" name="Submit" value="SUBMIT"></p>

</form>
</body>
</html>

add to database file (add_to_db.asp)

<html>
<head>
<title>Adding data to database</title>
</head>
<body>

Adding data to database...

<%@ Language="VBScript"%>
<%

'Dimension variables
Dim adoCon2  'Holds the database connection object
Dim rsAddFacility 'Holds the recordset for the new record to be added
Dim strSQL2  'Holds the SQL query to query the database

Set adoCon2=Server.CreateObject("ADODB.Connection") 'Create an ADO Connection Object

adoCon2.Open "DSN=profiles"
'Set an active connection to the Connection object using a DSN connection

Set rsAddFacility=Server.CreateObject("ADODB.Recordset")
'Create an ADO recordset object

'strSQL2="SELECT Facility.Facility_id, Facility.Facility_name, Facility.Facility_description, Facility.Street_address1, Facility_Street_address2, Facility.City, Facility.State, Facility.Zipcode, Facility.Website, Facility.Image FROM Facility;"
'Initialize the strSQL variable with an SQL statement to query the database

'rsAddFacility.CursorType=2
'Set the cursor type we are using so we can navigate through the recordset

'rsAddFacility.LockType=3
'Set the lock type so that the record is locked by ADO when it is updated

 rsAddFacility.Open strSQL2, adoCon2
'Open the recordset with the SQL query

rsAddFacility.AddNew
'Tell the recordset we are adding a new record to it

rsAddFacility.Fields("Facility_id")=Request.Form("Facility_id")
rsAddFacility.Fields("Facility_name")=Request.Form("Facility_name")
rsAddFacility.Fields("Facility_description")=Request.Form("Facility_description")
rsAddFacility.Fields("Street_address1")=Request.Form("Street_address1")
rsAddFacility.Fields("Street_address2")=Request.Form("Street_address2")
rsAddFacility.Fields("City")=Request.Form("City")
rsAddFacility.Fields("State")=Request.Form("State")
rsAddFacility.Fields("Zipcode")=Request.Form("Zipcode")
rsAddFacility.Fields("Website")=Request.Form("Website")
rsAddFacility.Fields("Image")=Request.Form("Image")
'Add a new record to the dataset

rsAddFacility.Update
'Write the updated recordset to the database

rsAddFacility.Close
Set rsAddFacility=Nothing
Set adoCon2=Nothing
'Reset the server objects

'Response.Redirect "display_profile_db.asp"

%>

</body>
</html> 

Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 11 April 2003 at 3:02pm
do you get an error or do you just not get any results?
Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 11 April 2003 at 3:04pm

P.S. your sql statement, just use

SELECT * FROM Facility

Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 11 April 2003 at 3:09pm

also watch what you comment and your punctuation

'strSQL2="SELECT Facility.Facility_id, Facility.Facility_name, Facility.Facility_description, Facility.Street_address1, Facility_Street_address2, Facility.City, Facility.State, Facility.Zipcode, Facility.Website, Facility.Image FROM Facility;"

the line in green is commented the semicolin in the blue text is unneeded. by using select * from facility you reduce the chance of typos.

P.S.S.S. you can't have Facility.Facility_id... etc. remove the part that says 'facility.' it is understood by the computer which table to open when you say FROM!

Back to Top
swatson View Drop Down
Newbie
Newbie


Joined: 11 April 2003
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote swatson Quote  Post ReplyReply Direct Link To This Post Posted: 11 April 2003 at 3:27pm

Thanks for your replies-

I don't get any error messages.

When I insert test data in the web form and hit submit, the html file appears to call add_to_db.asp (because the "Adding data to database" html line from the beginning of add_to_db.asp is returned).  However, none of the data that I enter in the form is actually submitted to the database.  Any ideas?

Thank you-

Stephanie Watson

Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 11 April 2003 at 3:45pm

did you make the changes i said to and then test it again. You don't even need the SQL SELECT statement. I included a rewritten file, try it and see if it works. REMEMBER: in asp coding the shorter the better, it reduces the chance of typo's. Don't add things to the end of the variables like rsaddfacility can be easily misspelled. i use 'rs' to make it simple. Also watch what you comment. you commented out your cursor and lock types.

Happy coding,

Paul Morgan

BEGIN VBSCRIPT

<%


Dim conn
Dim rs

Set conn = Server.CreateObject("ADODB.Connection")

conn.Open "DSN=profiles"

Set rs=Server.CreateObject("ADODB.Recordset")

rs.open "facility", conn
rs.CursorType=2
rs.LockType=3

rs.AddNew
  rs.Fields("Facility_id") = Request.Form("Facility_id")
  rs.Fields("Facility_name") = Request.Form("Facility_name")
  rs.Fields("Facility_description") = Request.Form("Facility_description")
  rs.Fields("Street_address1") = Request.Form("Street_address1")
  rs.Fields("Street_address2") = Request.Form("Street_address2")
  rs.Fields("City") = Request.Form("City")
  rs.Fields("State") = Request.Form("State")
  rs.Fields("Zipcode") = Request.Form("Zipcode")
  rs.Fields("Website") = Request.Form("Website")
  rs.Fields("Image") = Request.Form("Image")
rsAddFacility.Update
'Write the updated recordset to the database

conn.close
rs.close
rs = NOTHING
conn = NOTHING

Response.Redirect "display_profile_db.asp"

%> GOOD LUCK!!

Back to Top
swatson View Drop Down
Newbie
Newbie


Joined: 11 April 2003
Status: Offline
Points: 8
Post Options Post Options   Thanks (0) Thanks(0)   Quote swatson Quote  Post ReplyReply Direct Link To This Post Posted: 11 April 2003 at 3:55pm

Hello Paul -

Yes, I had made the changes you suggested.  Thanks for the tips.  I tried the web form with your version of the asp file and what got returned was the asp code in the browser.  Data doesn't get inserted into the database.  I have the database in the same folder (wwwroot) as the asp files so they should be able to find the database...?

Thank you-

Stephanie

Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 11 April 2003 at 4:32pm

i found my error. When i converted the name of rsAddFacility i never told it to update afterwards. change the line where it sayes "rsAddFacility.update" to "rs.update". Make sure you run it through your web server. that should do it

Back to Top
 Post Reply Post Reply Page  123>

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.