Click to See Complete Forum and Search --> : Entering a form data in a database.
FlagstaffRoy
10-06-2006, 08:26 PM
We have an online form ... the code is posted here ...
http://plumpix.com/form.htm
which our visitors will fillout and upon pressing Submit. It sends an email ... ASP code is here ...
http://plumpix.com/aspfile.htm
This works. Now we also want to insert form data in a MSSQL database.
The database table is as follows ...
http://plumpix.com/table.htm
How do I write the piece to insert data in database?
Any help appreciated.
Roy
jvanamali
10-07-2006, 07:48 AM
Write the below code in between objMail.send and resposne.redirect("thankyou.htm")
Dim Conn,sql
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=SQLOLEDB; Data Source = localhost; Initial Catalog = databasename; User Id = sa; Password= pwd"
Sql = "INSERT INTO Contacts(txtFirstname,txtLastName,txtPhone,txtComment,txtEmail) VALUES ('" & strFname & "','" & strEmail & "','" & strPhone & "','" & strComment & "','" & strEmail & "')"
Add the other fields also in a similar way
two more write write Set objMail = Nothing above response.redirect
and better use varchar in database than char for all the fields
FlagstaffRoy
10-15-2006, 08:51 PM
I made some changes. I changed language to aspmail and the database to Access. Problem I have now is that I can send the form but can't get data into database. I get NO error message 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
Table is pretty much this ...
http://plumpix.com/table.htm
Any help appreciated.
Roy
FlagstaffRoy
10-15-2006, 09:14 PM
Can I rewrite the ASP code this way? ...
http://plumpix.com/aspfile3.htm
I am just wonder whether I can separate database and emailing functions.