By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,660 Members | 1,593 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,660 IT Pros & Developers. It's quick & easy.

Unable to Add Record to DB Table Using ASP

P: 10
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:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <body>
  3.  
  4. <form method="post" action="inventory_add.asp">
  5. <table>
  6. <tr>
  7. <td>sku:</td>
  8. <td><input name="sku"></td>
  9.  
  10. </tr><tr>
  11. <td>model</td>
  12. <td><input name="model"></td>
  13.  
  14.  
  15. </tr><tr>
  16. <td>type</td>
  17. <td><input name="type"></td>
  18.  
  19.  
  20. </tr><tr>
  21. <td>color</td>
  22. <td><input name="color"></td>
  23.  
  24. </tr><tr>
  25. <td>sizing</td>
  26. <td><input name="sizing"></td>
  27.  
  28.  
  29. </tr><tr>
  30. <td>quantity</td>
  31. <td><input name="quantity"></td>
  32.  
  33. </tr>
  34. </table>
  35. <br /><br />
  36. <input type="submit" value="Add New">
  37. <input type="reset" value="Cancel">
  38. </form>
  39.  
  40. </body>
  41. </html> 
And here is the inventory_add.asp script:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.  
  4. <script type="text/javascript">
  5. function goback()
  6. {
  7. history.go(-1)
  8. }
  9. </script>
  10.  
  11. </head>
  12.  
  13.  
  14. <body>
  15. <%
  16. set conn=Server.CreateObject("ADODB.Connection")
  17. conn.Provider="Microsoft.Jet.OLEDB.4.0"
  18. conn.Open(Server.Mappath("/clientlogin/db/tmg.mdb"))
  19.  
  20.  
  21.  
  22. sql="INSERT INTO [Inventory] (sku,itemnumber,"
  23. sql=sql & "style,color,quantity,location)"
  24. sql=sql & " VALUES "
  25. sql=sql & "'" & Request.Form("sku") & "',"
  26. sql=sql & "'" & Request.Form("itemnumber") & "',"
  27. sql=sql & "'" & Request.Form("style") & "',"
  28. sql=sql & "'" & Request.Form("color") & "',"
  29. sql=sql & "'" & Request.Form("quantity") &"',"
  30. sql=sql & "'" & Request.Form("location") & "'"
  31.  
  32. on error resume next
  33. conn.Execute sql,recaffected
  34. if err<>0 then
  35.   Response.Write("Please contact Tech Support - 904.733.0030")
  36. else
  37.   response.redirect "http://www.shipping-and-handling.com/clientlogin/tmg/update.asp"
  38. end if
  39. conn.close
  40. %>
  41.  
  42. </body>
  43. </html> 
  44.  
  45. </body>
  46. </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
Mar 25 '14 #1

✓ answered by Rabbit

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.

Share this Question
Share on Google+
4 Replies


Rabbit
Expert Mod 10K+
P: 12,370
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.
Mar 25 '14 #2

P: 10
This is my error now: Microsoft JET Database Engine error '80040e14'

Syntax error in INSERT INTO statement.

/clientlogin/iko/inventory_add.asp, line 31
Mar 26 '14 #3

P: 10
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!
Mar 26 '14 #4

Rabbit
Expert Mod 10K+
P: 12,370
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:
Expand|Select|Wrap|Line Numbers
  1. INSERT INTO tableName (column list)
  2. VALUES (value list)
In your code, you were missing the enclosing parentheses on the value list.
Mar 26 '14 #5

Post your reply

Sign in to post your reply or Sign up for a free account.