Click to See Complete Forum and Search --> : Need help with inserting data using ASP into Access db.


FlagstaffRoy
10-16-2006, 06:37 PM
Problem I have is that I can email info in my form but can't get data into an access database. I get NO error messages and log shows nothing either. I have created an ODBC entry to my database "H10_sun", and placed my database contacts.mdb under my sites's root directory.

The form is here...

http://plumpix.com/form2.htm

ASP code is here ...

http://plumpix.com/aspfile2.htm

Access table pretty much looks like this ...

http://plumpix.com/table.htm

Any help appreciated.
Roy

russell
10-16-2006, 09:25 PM
1. you aren't executing your sql
2. nothing else gets executed after your response.redirect
3. the on error resume next will suppress error messages, making it impossible to debug, should comment that out when testing/developing
4. the sql insert is all weird and you aren't inserting the form values.
5. you have an extra end if at the end -- and remember that whole block after the redirect never gets executed anyway.

replace this line with everything below:
Sql = "INSERT INTO Contacts (Financing, Models, Spanish, First, Last, Phone, Comment, email, address, city, state, zip, timeline) VALUES ('%%chkFinancing%%','%%chkFloorPlans%%','%%chkSpanish%%','%%txtFirstName%%','%%txtLastName%%','%%txt Phone%%','%%txtComment%%','%%txtEmail%%','%%txtAddress%%','%%txtCity%%','%%selState%%','%%txtZip%%', '%%timeline%%')"

Dim chkFinancing
Dim chkFloorPlans
Dim chkSpanish
Dim txtFirstName
Dim txtLastName
Dim txtPhone
Dim txtComment
Dim txtEmail
Dim txtAddress
Dim txtCity
Dim selState
Dim txtZip
Dim timeline

chkFinancing = Replace(Request("chkFinancing"), "'", "''")
chkFloorPlans = Replace(Request("chkFloorPlans"), "'", "''")
chkSpanish = Replace(Request("chkSpanish"), "'", "''")
txtFirstName = Replace(Request("txtFirstName"), "'", "''")
txtLastName = Replace(Request("txtLastName"), "'", "''")
txtPhone = Replace(Request("txtPhone"), "'", "''")
txtComment = Replace(Request("txtComment"), "'", "''")
txtEmail = Replace(Request("txtEmail"), "'", "''")
txtAddress = Replace(Request("txtAddress"), "'", "''")
txtCity = Replace(Request("txtCity"), "'", "''")
selState = Replace(Request("selState"), "'", "''")
txtZip = Replace(Request("txtZip"), "'", "''")
timeline = Replace(Request("timeline"), "'", "''")

Sql = "INSERT INTO Contacts (Financing, Models, Spanish, First, Last, Phone, Comment, " &_
"email, address, city, state, zip, timeline) VALUES (" &_
"'" & chkFinancing & "', " &_
"'" & chkSpanish & "', " &_
"'" & txtFirstName & "', " &_
"'" & txtLastName & "', " &_
"'" & txtPhone & "', " &_
"'" & txtComment & "', " &_
"'" & txtEmail & "', " &_
"'" & txtAddress & "', " &_
"'" & txtCity & "', " &_
"'" & selState & "', " &_
"'" & timeline & "')"

conn.execute sql

FlagstaffRoy
10-16-2006, 11:59 PM
Russell, many, many kudos. It works perfect with MySQL database. I had problem with Access, so I decided to abandon it and use MySQL. I am posting the final code for others to use... Thanks, Ron

<%
Dim Conn,sql
Dim chkFinancing
Dim chkFloorPlans
Dim chkSpanish
Dim txtFirstName
Dim txtLastName
Dim txtPhone
Dim txtComment
Dim txtEmail
Dim txtAddress
Dim txtCity
Dim selState
Dim txtZip
Dim timeline

' database connection
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "H10_sun"

' change to address of your own SMTP server
strHost = "100.1.1.181"
strRecepient = "myemail@yahoo.com"

If Request("Send") <> "" Then

Set Mail = Server.CreateObject("Persits.MailSender")
' enter valid SMTP host
Mail.Host = strHost

Mail.From = Request("txtFirstName")
' & " " & Request("txtLastName")
Mail.AddAddress strRecepient

' message subject
Mail.Subject = "Information Request"
' message body
Mail.Body = "ONLINE REQUEST INFORMATION: " & vbcrlf & "==================================================================" & vbcrlf & "Financing Info: " & Request("chkFinancing") & vbcrlf & "Models Info: " & Request("chkFloorPlans") & vbcrlf & "Spanish Help: " & Request("chkSpanish") & vbcrlf & "First Name: " & Request("txtFirstName") & vbcrlf & "Last Name: " & Request("txtLastName") & vbcrlf & "Phone: " & Request("txtPhone") & vbcrlf & "Comment: " & Request("txtComment") & vbcrlf & "Email: " & Request("txtEmail") & vbcrlf & "Address: " & Request("txtAddress") & vbcrlf & "City: " & Request("txtCity") & vbcrlf & "State: " & Request("selState") & vbcrlf & "Zip: " & Request("txtZip") & vbcrlf & "Want to move to new house within: " & Request("timeline")


chkFinancing = Replace(Request("chkFinancing"), "'", "''")
chkFloorPlans = Replace(Request("chkFloorPlans"), "'", "''")
chkSpanish = Replace(Request("chkSpanish"), "'", "''")
txtFirstName = Replace(Request("txtFirstName"), "'", "''")
txtLastName = Replace(Request("txtLastName"), "'", "''")
txtPhone = Replace(Request("txtPhone"), "'", "''")
txtComment = Replace(Request("txtComment"), "'", "''")
txtEmail = Replace(Request("txtEmail"), "'", "''")
txtAddress = Replace(Request("txtAddress"), "'", "''")
txtCity = Replace(Request("txtCity"), "'", "''")
selState = Replace(Request("selState"), "'", "''")
txtZip = Replace(Request("txtZip"), "'", "''")
timeline = Replace(Request("timeline"), "'", "''")

Sql = "INSERT INTO Contacts (chkFinancing, chkFloorPlans, chkSpanish, txtFirstName, txtLastName, txtPhone, txtComment, " &_
"txtEmail, txtAddress, txtCity, selState, txtZip, timeline) VALUES (" &_
"'" & chkFinancing & "', " &_
"'" & chkFloorPlans & "', " &_
"'" & chkSpanish & "', " &_
"'" & txtFirstName & "', " &_
"'" & txtLastName & "', " &_
"'" & txtPhone & "', " &_
"'" & txtComment & "', " &_
"'" & txtEmail & "', " &_
"'" & txtAddress & "', " &_
"'" & txtCity & "', " &_
"'" & selState & "', " &_
"'" & txtZip & "', " &_
"'" & timeline & "')"

Mail.Send
Response.write sql

conn.execute sql
conn.close

Response.Redirect "Thankyou.htm"
End if
%>