SQL INSERT INTO Error..

Discussion in 'Technology' started by Jason Bourne, Nov 21, 2005.

Users Viewing Thread (Users: 0, Guests: 0)

  1. Jason Bourne

    Jason Bourne Registered User

    Joined:
    Oct 14, 2002
    Messages:
    5,337
    Likes Received:
    0
    SQL INSERT INTO Error..

    I'm trying to create a simple subscription page in ASP..

    After spending literally hours settin up IIS.. I decided to try and script a quick HTML form that posts data to an asp page to insert the data into the relevant fields in a database.

    I created all files, the Database and HTML files are fine but for some reason I keep gettin this error on my SQL script..

    ------------------------------------------------------------------------

    Error Type:
    Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
    [Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
    /DVD/Subscribe.asp, line 26

    ------------------------------------------------------------------------

    The ASP script file is as follows..

    ------------------------------------------------------------------------

    <HTML>
    <HEAD>
    <TITLE>
    Member Subscription
    </TITLE>
    </HEAD>

    <BODY>
    <%
    'Retrieve the variables from the form
    Salutation = Request.querystring( "Salutation" )
    Forename = Request.querystring( "Forename" )
    Surname = Request.querystring( "Surname" )
    Email = Request.querystring( "Email" )
    %>

    <%
    'Open the database connection
    Set Con = Server.CreateObject( "ADODB.Connection" )
    Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Members.mdb")
    %>

    <%
    'Add new member
    sqlAddMember = "INSERT INTO Members ( Member Salutation, Member Forename, Member Surname, Member Email Address ) VALUES ( '" & Salutation & "', '"& Forename & "', '" & Surname & "', '" & Email & "' )"
    Con.Execute sqlAddMember

    'Display confirmation message to the user.
    Response.Write(Salutation & Surname & " you have been successfully added to our email list")
    %>

    ------------------------------------------------------------------------

    Can any of you guys see where I'm going wrong?

    *Edit*

    After a quick further "mess about" I've came to the conclusion that the error is created by the line "Con.Execute sqlAddMember"

    Still dunno how to fix it though.. :spangled: :(
  2. 1615634792921.png
  3. Conway

    Conway helmet Staff

    Joined:
    Apr 16, 2003
    Messages:
    11,628
    Likes Received:
    521
    Location:
    Newcastle
    It looks to me like it could be the line above... something may not be right with the information you are trying to assign to the variable.

    I don't know enough about MySQL to spot anything obvious.
  4. Jason Bourne

    Jason Bourne Registered User

    Joined:
    Oct 14, 2002
    Messages:
    5,337
    Likes Received:
    0
    Thit seemed to work..

    -------------------------------------------------------------------------------------

    "INSERT INTO Members (`Member Salutation`, `Member Forename`) VALUES ( 'foo', 'bar' )"

    -------------------------------------------------------------------------------------

    So its the variable that are causing the problem..
    I kinda thought it might be this as I can't get my head around what the HTML text boxes are classed as when called in the calling variables section at the top.

    In the example I was give they were Request.form (blah) but I was unsure if that mean't that each of the text boxes were on a different form..

    So I used Querystring.. I'm confused..
  5. Jason Bourne

    Jason Bourne Registered User

    Joined:
    Oct 14, 2002
    Messages:
    5,337
    Likes Received:
    0
    Think I might have it sorted now... but have to wait till I finish work to test out my theory.. :(
  6. BRID

    BRID Has name in red. Staff

    Joined:
    Jan 31, 2003
    Messages:
    8,341
    Likes Received:
    218
    Location:
    Ever changing
    `Member Salutation`, `Member Forename`


    The quote marks around those field names are wrong. They should either be ' marks.... or realistically you shouldnt use them at all - in that case you are best off calling your fields by a single name such as MemberSalutation and MemberForename to prevent any screwups.

    Hope that helps.
  7. trance_fan

    trance_fan Registered User

    Joined:
    Nov 7, 2002
    Messages:
    9,079
    Likes Received:
    0
    :up:

    Not a fan of ASP it's soooo sodding fickle.

    All will be working well then for no apparent reason it will decide that your code is wrong and break :cry:
  8. Jason Bourne

    Jason Bourne Registered User

    Joined:
    Oct 14, 2002
    Messages:
    5,337
    Likes Received:
    0
    Sorted it.. here is the fixed script...

    ----------------------------------------------------------------------------

    <HTML>
    <HEAD>
    <TITLE>
    Member Subscription
    </TITLE>
    </HEAD>

    <BODY>
    <%
    'Retrieve the variables from the form
    Salutation = Request.Form( "Salutation" )
    Forename = Request.Form( "Forename" )
    Surname = Request.Form( "Surname" )
    Email = Request.Form( "Email" )
    %>

    <%
    'Open the database connection
    Set Con = Server.CreateObject( "ADODB.Connection" )
    Con.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Members.mdb")
    %>

    <%
    'Add new member
    sqlAddMember ="INSERT INTO Members ( `Member Salutation`, `Member Forename`, `Member Surname`, `Member Email Address`) VALUES ('" & Salutation & "', '" & Forename & "', '" & Surname & "', '" & Email & "')"

    con.execute sqlAddMember
    %>

    <%

    'Display confirmation message to the user.
    Response.Write( Salutation & Surname & "you have been successfully added to our email list")
    %>

    --------------------------------------------------------------------------

    Just one more thing to sort and it should just be a simple &nbsp insertion :D

    Cheers for the help guys :up:

Share This Page