|
-
July 11th, 2002, 07:34 AM
#1
ASP and MSAccess Insert Help
I'm messing around with ASP a little bit since I've got php down. Well here it goes
I'm using a msaccess database with a dsn connection. The html form has text boxes on it
for name, zip, address, phone number. In the db1.mdb there are 2 tables one for storing the name and one for storing the other information. I can't seem to get the correct syntax to
insert the html form into the database. So how would I do this? Insert the data from the forms
into the database?
Heres what I've got so far
Code:
<%
Dim Conn
Dim SqlName
Dim SqlAddress
strName = Request.Form("txtName")
strAddress = Request.Form("txtaddress")
strCity = Request.Form("txtCity")
strState = Request.Form("txtState")
strZip = Request.Form("txtZip")
strPhone = Request.Form("txtPhone")
strEmail = Request.Form("txtEmail")
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ="DSN=db1.mdb"
SqlName="INSERT INTO Name(Name) Values('" & strName '")"
Conn.Execute(SqlName)
SqlAddress="INSERT INTO Address(Address,City,State,Zip,Phone,Email) VALUES('" & strAddress & '","' & strCity & '","' & strState & '","' & strZip & '","' & strPhone & '","' & strEmail '")"
Conn.Execute(SqlAddress)
%>
I'm more of a mySQL person but it's the syntax or how I might insert the data from the html forms into the the database and put it in the correct tables and rows.
-
July 11th, 2002, 07:54 AM
#2
Member
The problem may be in your single / double quotes (?)
try:
SqlName="INSERT INTO Name(Name) Values('" & strName & "')"
Conn.Execute(SqlName)
SqlAddress="INSERT INTO Address(Address,City,State,Zip,Phone,Email) VALUES('" & strAddress & "','" & strCity & "','" & strState & "','" & strZip & "','" & strPhone & "','" & strEmail "')"
Conn.Execute(SqlAddress)
-
July 11th, 2002, 08:22 AM
#3
yeap it was. I found an example using a guestbook it showed how to do it. I just copied and pasted what they had and changed the variables to mine. All those quotes get confusing. But it's working now.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|