|
Add form components to a database
First off, I will tell you that it has been over a year since I have messed with ACCESS and ASP code at college.
Here is my form page
- Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Untitled</title>
</head>
<body>
<H1>Contact Information</H1>
<FORM NAME="ContactForm" METHOD="POST" ACTION="add2db.asp">
Name:<INPUT NAME="Name" size="45"> <BR>
Address 1: <INPUT NAME="Adr1" size="45"> <BR>
Address 2:<INPUT NAME="Adr2" size="45"> <BR>
City: <INPUT NAME="City" size="18"> State:<INPUT NAME="State" size="2"> Zip Code: <INPUT NAME="Zip" size="5" type="int"><BR>
Email:<INPUT NAME="Email" size="51"><BR>
Phone1:<INPUT NAME="Phone1" size="51"><BR>
Phone2:<INPUT NAME="Phone2" size="51"><BR>
Phone3:<INPUT NAME="Phone3" size="51"><BR>
<H3>What is the nature of your project?</H3>
<INPUT TYPE="radio" NAME="PlanType" VALUE="Religious"> Religious ---> <SELECT NAME="Plans" SIZE="1"><OPTION SELECTED>Worship Centers<OPTION>Youth Centers<OPTION>Multi-Purpose</SELECT><BR>
<INPUT TYPE="radio" NAME="PlanType" VALUE="Educational"> Educational <BR>
<INPUT TYPE="radio" NAME="PlanType" VALUE="Residential"> Residential <BR>
<INPUT TYPE="radio" NAME="PlanType" VALUE="Commercial"> Commercial <BR>
If Religious - Seating Capacity? <input name="Seating" type=int size="5"> <BR>
<H3>Any more information?</H3><BR>
<textarea name="Other" cols=48 rows=4></textarea><BR>
<P>
<INPUT TYPE=SUBMIT> <INPUT TYPE=RESET>
</FORM>
</body>
</html>
Here is my ASP code:
- Code: Select all
<%@ Language="VBScript" %>
<% Option Explicit %>
<html>
<head>
<title>Form to database</title>
</head>
<body>
<%
'declare your variables
Dim Name, Adr1, Adr2, City, State, Zip, Email, Phone1, Phone2, Phone3, PlanType, Plans, Seating, Other
Dim sConnString, connection, sSQL
'Receiving values from Contact, assign the values entered to variables
Name = Request.Form("Name")
Adr1 = Request.Form("Adr1")
Adr2 = Request.Form("Adr2")
City = Request.Form("City")
State = Request.Form("State")
Zip = Request.Form("Zip")
Email = Request.Form("Email")
Phone1 = Request.Form("Phone1")
Phone2 = Request.Form("Phone2")
Phone3 = Request.Form("Phone3")
PlanType = Request.Form("PlanType")
Plans = Request.Form("Plans")
Seating = Request.Form("Seating")
Other = Request.Form("Other")
'declare SQL statement that will query the database
sSQL = "INSERT into ContactInfo (Name, Adr1, Adr2, City, State, Zip, Email, Phone1, Phone2, Phone3, PlanType, Plans, Seating, Other, ) values ('" & Name & "','" & Adr1 & "','" & Adr2 & "','" & City & "','" & State & "','" & Zip & "', '" & Email & "','" & Phone1 & "','" & Phone2 & "','" & Phone3 & "','" & PlanType & "','" & Plans & "','" & Seating & "', '" & Other & "')"
'define the connection string, specify database
'driver and the location of database
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source="ELRContact.mdb")
'create an ADO connection object
Set connection = Server.CreateObject("ADODB.Connection")
'Open the connection to the database
connection.Open(sConnString)
'execute the SQL
connection.execute(sSQL)
response.write "The form information was inserted successfully."
'Done. Close the connection object
connection.Close
Set connection = Nothing
%>
</body>
</html>
I have created a database in ACCESS with all of the components, Name, Phone1, Email, PlanType, etc... My problem is this. It doesn't work. I fill in all of the blanks, click SUBMIT, and it puts me over to add2db. asp. The page puts the entire asp code on the screen, and does not update the database.
All of these files are in the same folder. The database is called ELRContact.mdb with one table called ContactInfo. I am simply wanting information to enter the database.
I have tried accessing this through Opera browser, as well as IE, but it doesnt work. I seemt o be missing somethign, but I am not sure what. Any help would be greatly appreciated.
GW
|