Unable to Add Record to DB Table Using ASP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • aaronsah
    New Member
    • Feb 2014
    • 10

    Unable to Add Record to DB Table Using ASP

    Hello,

    I am attempting to add a record to a database using an HTML page that collects the data entered and sends it to an ASP script to then write to an online database. However, in testing, I am unable to successfully execute the command.

    Here is the code for the HTML portion:
    Code:
    <html>
    <body>
    
    <form method="post" action="inventory_add.asp">
    <table>
    <tr>
    <td>sku:</td>
    <td><input name="sku"></td>
    
    </tr><tr>
    <td>model</td>
    <td><input name="model"></td>
    
    
    </tr><tr>
    <td>type</td>
    <td><input name="type"></td>
    
    
    </tr><tr>
    <td>color</td>
    <td><input name="color"></td>
    
    </tr><tr>
    <td>sizing</td>
    <td><input name="sizing"></td>
    
    
    </tr><tr>
    <td>quantity</td>
    <td><input name="quantity"></td>
    
    </tr>
    </table>
    <br /><br />
    <input type="submit" value="Add New">
    <input type="reset" value="Cancel">
    </form>
    
    </body>
    </html>
    And here is the inventory_add.a sp script:
    Code:
    <html>
    <head>
    
    <script type="text/javascript">
    function goback()
    {
    history.go(-1)
    }
    </script>
    
    </head>
    
    
    <body>
    <%
    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open(Server.Mappath("/clientlogin/db/tmg.mdb"))
    
    
    
    sql="INSERT INTO [Inventory] (sku,itemnumber,"
    sql=sql & "style,color,quantity,location)"
    sql=sql & " VALUES "
    sql=sql & "'" & Request.Form("sku") & "',"
    sql=sql & "'" & Request.Form("itemnumber") & "',"
    sql=sql & "'" & Request.Form("style") & "',"
    sql=sql & "'" & Request.Form("color") & "',"
    sql=sql & "'" & Request.Form("quantity") &"',"
    sql=sql & "'" & Request.Form("location") & "'"
    
    on error resume next
    conn.Execute sql,recaffected
    if err<>0 then
      Response.Write("Please contact Tech Support - 904.733.0030")
    else
      response.redirect "http://www.shipping-and-handling.com/clientlogin/tmg/update.asp"
    end if
    conn.close
    %>
    
    </body>
    </html> 
    
    </body>
    </html>
    The error that is happening is my own - the script throws the "Please Contact Tech Support" error. So I am not sure what is occurring.

    I checked and made sure that SKU and Quantity are Number fields in the database, and everything else is Short Text.

    Any assistance is much appreciated.

    Thanks
  • Rabbit
    Recognized Expert MVP
    • Jan 2007
    • 12517

    #2
    You should write out the actual error message and number and not a generic one that you created. The actual error message will tell you more about what the problem is.

    Comment

    • aaronsah
      New Member
      • Feb 2014
      • 10

      #3
      This is my error now: Microsoft JET Database Engine error '80040e14'

      Syntax error in INSERT INTO statement.

      /clientlogin/iko/inventory_add.a sp, line 31

      Comment

      • aaronsah
        New Member
        • Feb 2014
        • 10

        #4
        Well.. I am not entirely sure how I fixed it, but I fixed it... the suggestion to change out the error message was the correct one as it definitely helped me troubleshoot! Thanks Rabbit!

        Comment

        • Rabbit
          Recognized Expert MVP
          • Jan 2007
          • 12517

          #5
          Now that we know where to look for the error, I can figure out what went wrong.

          The insert SQL syntax should look like this:
          Code:
          INSERT INTO tableName (column list)
          VALUES (value list)
          In your code, you were missing the enclosing parentheses on the value list.

          Comment

          Working...