Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Feb 2007
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Accessing HTML form variables in ASP.

    I have this code:

    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.

  • #2
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    Request.Form("elementname")

    That said, your SQL is invalid. Especially for Access and dates.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/

  • #3
    New Coder
    Join Date
    Feb 2007
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts
    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

  • #4
    Senior Coder
    Join Date
    Dec 2002
    Location
    Arlington, Texas USA
    Posts
    1,072
    Thanks
    4
    Thanked 8 Times in 8 Posts
    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.

  • #5
    Senior Coder nikkiH's Avatar
    Join Date
    Jun 2005
    Location
    Near Chicago, IL, USA
    Posts
    1,973
    Thanks
    1
    Thanked 32 Times in 31 Posts
    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.

    If this post contains any code, I may or may not have tested it. It's probably just example code, so no getting knickers in a bunch over a typo, OK? If it doesn't have basic error checking in it, such as object detection or checking if objects are null before using them, put that in there. I'm giving examples, not typing up your whole app for you. You run code at your own risk.
    Bored? Visit
    http://www.kaelisspace.com/


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •