locked
Server 500 Error with access form RRS feed

  • Question

  • Hi

    I have a website which users are required to fill out a form which populates an access 2007 database.  My users keep getting adhoc Server 500 errors.  I and a few others have tested the form and it has worked successfully and none of us have had the error, but it is obviously happening.  My site is hosted with Fasthosts, and they are saying it is my code! 

    Here is a copy of my code - is anyone able to pick the holes in it and possibly diagnose the problem?  I was told it might be to do with the opening and closing of the database connections, but I am not sure.

     

    <%
    ' Declaring variables
    Dim forename, surname, age, address1, address2, address3, country, telephone, data_source, con, sql_insert

    ' A Function to check if some field entered by user is empty
    Function ChkString(string)
        If string = "" Then string = " "
        ChkString = Replace(string, "'", "''")
    End Function

    ' Receiving values from Form
    forename = ChkString(Request.Form("forename"))
    surname = ChkString(Request.Form("surname"))
    address1 = ChkString(Request.Form("address1"))
    address2 = ChkString(Request.Form("address2"))
    address3 = ChkString(Request.Form("address3"))
    country = ChkString(Request.Form("country"))
    telephone = ChkString(Request.Form("telephone"))

    data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
    Server.MapPath("form.mdb")

    sql_insert = "insert into users (forename, surname, address1, address2, address3, country, telephone  ) values('" & forename & "', '" & surname & "', '" & address1 & "', '" & address2 & "' , '" & address3 & "', '" & country & "', '" & telephone & "')"

    ' Creating Connection Object and opening the database
    Set con = Server.CreateObject("ADODB.Connection")
    con.Open data_source
    con.Execute sql_insert

    ' Done. Close the connection
    con.Close
    Set con = Nothing


    Response.Redirect "thank_you.html"

    %>
    Tuesday, November 1, 2011 9:15 AM

Answers