hornsby100 03-06-2007, 12:11 PM I have this code:
Dim cnMyDb
Dim sql
Dim recsaff
If Request("btnSub") <> "" then
Set cnMyDb = Server.CreateObject("ADODB.Connection")
cnMyDb.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & _
Server.MapPath("../data/bookingcalendar.mdb") & ";"
sql = "INSERT INTO "client_database" ("", "Date_Required_To", "Date_Required_From", "Firstname", "Surname", "Number_of_People", "Names_of_People", "Address_Line_1", "Address_Line_2", "Town/City", "County", "Postcode", "Country", "Phone_Number", "Mobile_Number", "Email_Address",)
VALUES ("value1", "value2", "value3", "value4", "value5", "value6")"
cnMyDb.Execute sql, recsaff
cnMyDb.close
End If
How do i substitute "value1" etc. for variables received from a html form?
Thanks for your help.
nikkiH 03-06-2007, 02:21 PM Request.Form("elementname")
That said, your SQL is invalid. Especially for Access and dates.
hornsby100 03-07-2007, 05:39 PM Ive changed the code to:
Dim con
Dim sql_insert
Dim data_source
Dim Date_Required_From
Dim Date_Required_To
Dim Firstname
Dim Surname
Dim Number_of_People
Dim Names_of_People
Dim Address_Line_1
Dim Address_Line_2
Dim Town_City
Dim County
Dim Postcode
Dim Country
Dim Phone_Number
Dim Mobile_Number
Dim Email_Address
Function ChkString(string)
If string = "" Then string = " "
ChkString = Replace(string, "'", "''")
End Function
Date_Required_From = ChkString(Request.Form("Date_Required_From"))
Date_Required_To = ChkString(Request.Form("Date_Required_To"))
Firstname = ChkString(Request.Form("Firstname"))
Surname = ChkString(Request.Form("Surname"))
Number_of_People = ChkString(Request.Form("Number_of_People"))
Names_of_People = ChkString(Request.Form("Names_of_People"))
Address_Line_1 = ChkString(Request.Form("Address_Line_1"))
Address_Line_2 = ChkString(Request.Form("Address_Line_2"))
Town_City = ChkString(Request.Form("Town_City"))
County = ChkString(Request.Form("County"))
Postcode = ChkString(Request.Form("Postcode"))
Country = ChkString(Request.Form("Country"))
Phone_Number = ChkString(Request.Form("Phone_Number"))
Mobile_Number = ChkString(Request.Form("Mobile_Number"))
Email_Address = ChkString(Request.Form("Email_Address"))
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
Server.MapPath("../data/bookingcalendar.mdb")
sql_insert = "insert into clientdatabase ([Date_Required_From], [Date_Required_To], [Firstname], [Surname], [Number_of_People], [Names_of_People], [Address_Line_1], [Address_Line_2], [Town_City], [County], [Postcode], [Country], [Phone_Number], [Mobile_Number], [Email_Address]) values ('" & _
Date_Required_From & "', '" & Date_Required_To & "', '" & Firstname & "', '" & Surname & "', '" & Number_of_People & "', '" & Names_of_People & "', '" & Address_Line_1 & "', '" & Address_Line_2 & "', '" & Town_City & "', '" & County & "', '" & Postcode & "', '" & Country & "', '" & Phone_Number & "', '" & Mobile_Number & "', '" & Email_Address & "' )"
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_insert
con.close
Set con = Nothing
When i enter data into the forms and press submit to send it to this page with the code from above i get the following error:
Microsoft JET Database Engine error '80040e37'
Could not find output table 'clientdatabase'.
/finalacknowlegdement.asp, line 89
My database is called bookingcalendar.mdb and the table inside i want the data to be sent to is named clientdatabase
Can anyone help me with this problem?
Thanks
miranda 03-07-2007, 06:01 PM have you confirmed that the table name is spelled the same in your SQL insert as it is in the database?
Also do a response write on the database path and make sure that you are pointing to the correct database
Response.Write Server.MapPath("../data/bookingcalendar.mdb")
I have seen instances where people had an older version of a database that they were pointing to and didn't understand why the error (the table wasn't in the older version)
By the way, it is never a good idea to put the database where it can be accessed directly via the web. it is always better to put it outside the root directory whenever possible.
nikkiH 03-07-2007, 07:03 PM Once it finds the table, you may have an issue with those dates, if they actually are stored as dates not text.
Last I checked, you needed #yourvalue# (hash signs) for dates, not single quotes. It's been awhile since I've used Access though.
|
|