473,396 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

SQL refuses to believe it works

92
How Do,

I have a rather simple website, which has some SQL embedded in the ASP to write user data to the underlying mdb database.

The first SQL statement looks up all the records in the database to help produce the required output which is a single string value which is the Customer's Order to be made in store for pickup. The second is to write the string into the database, and keeps shouting about a syntax error in the INSERT INTO statement. I however, cannot for the life of me find one.

I am more than aware that this is very poorly written and has absolutely no security features etc but they aren't necessary at the moment. All I need to know is how to get the Order in to the Database.

It is to be written to 'tblorder' into the fields 'username' and 'order' - both of which are text fields.

The database is properly shared and can be written to elsewhere on the site. The username comes from the username that is stored in the cookie 'UserName' and the product name from the recordset through indexing.

The String value is generated correctly, it just won't insert into the database.


Many Thanks,


NDayave


Expand|Select|Wrap|Line Numbers
  1. <html>
  2.  
  3. <head>
  4. <style>
  5. body{background: white)
  6. </style>
  7. <link rel="stylesheet" type="text/css" href="Main.css">
  8. <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
  9. <title>Our Products</title>
  10. </head>
  11.  
  12. <body>
  13. <%
  14. if request.cookies("UserName")="" then
  15.     response.write("<P align='Center'>You must be logged in to order from this page, please click <a target=Main href=login.asp>here</a> to log in, or click<a target=Main href=new_user.asp> here </a> if you are new to this site.</P>")
  16. else
  17. Dim Conn, Rs, sql
  18. Set Conn = Server.CreateObject("ADODB.Connection")
  19. Set Rs = Server.CreateObject("ADODB.Recordset")
  20. Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("HeyPesto.mdb")
  21. sql= "SELECT * FROM tblproducts;"
  22. Rs.Open sql, Conn
  23.  
  24. dim index, order
  25. index = 1
  26. order = ""
  27.  
  28.  
  29. do While not Rs.EOF
  30. If request.form("amount" & index) > 0 Then
  31.     order = order & request.cookies("UserName") & Rs("name") & request.form("amount" & index)
  32. end if
  33.  
  34. Rs.MoveNext
  35. index = index + 1
  36. loop
  37.  
  38.  
  39. Response.Write(order)
  40.  
  41.  
  42. Dim connorder, strConnorder, Rsorder
  43. Set connorder = Server.CreateObject("ADODB.Connection")
  44. strConnorder = "Provider=Microsoft.Jet.OLEDB.4.0; " & _
  45. "Data Source=" & Server.MapPath("HeyPesto.mdb") & "; " & _
  46. "User ID=; Password="
  47. connorder.Open strConnorder
  48. Set Rsorder = connorder.Execute ("INSERT INTO tblorder(username,order) VALUES (" & request.cookies("UserName") & "','" & order & "')" )
  49.  
  50. Rs.Close
  51.  
  52. Set Rs = Nothing
  53. Set Conn = Nothing
  54.  
  55. Rsorder.Close
  56.  
  57. Set Rsorder = Nothing
  58. Set Connorder = Nothing
  59. end if
  60. %>
  61.  
  62. </body>
  63.  
  64. </html>
Mar 24 '09 #1
5 1731
jhardman
3,406 Expert 2GB
you are missing a single quote mark:
Expand|Select|Wrap|Line Numbers
  1. Set Rsorder = connorder.Execute ("INSERT INTO tblorder(username,order) VALUES ('" & request.cookies("UserName") & "','" & order & "')" )
Please let me know if this helps.

Jared
Mar 26 '09 #2
NDayave
92
Thanks for the suggestion.

Still throwing up error messages though:

Microsoft JET Database Engine error '80040e14'

Syntax error in INSERT INTO statement.

/Order.asp, line 49

NDayave
Mar 26 '09 #3
jhardman
3,406 Expert 2GB
in general, the best way to troubleshoot sql is to response.write the sql statement, then plug it in to a query analyzer. Did you say you were using sql server? there should be an analyzer built in to the management studio.
Mar 26 '09 #4
NDayave
92
Turns out 'order' requires square brackets when it is a field name.

Thanks a lot for your input, it works fine now.

NDayave
Mar 26 '09 #5
jhardman
3,406 Expert 2GB
Ah yes, "order" is a sql reserved word. Any field name can be put in square brackets without bothering SQL, so some people do it always, the rest should make sure they never use reserved words (or words with reserved characters) for field names.
Mar 27 '09 #6

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

Similar topics

11
by: lkrubner | last post by:
We are working on a website that is here: http://www.lauradenyes.com/ The site was working till I put up an .htaccess file that was suppose to redirect all html files to the PHP parser. The...
0
by: Wayne Aprato | last post by:
Can anyone please help me with the following madness in Access 2003 (2000 file format). I am using 2 similar funtions, the first which works fine to save reports as snapshots: On Error Resume...
1
by: Ebrahim | last post by:
This message is in reply to a prev 1 . My application refues to close . Some one had suggested that I might have threads running.. but i solved that problem too . The app still refuses to close...
2
by: Beeeeeves | last post by:
Why whenever I create a project in c#, when I compile it, it has got the resulting executable TWICE in TWO different directories - obj\debug and bin\debug. WHY? Sometimes when I'm trying to debug...
7
by: Daniel | last post by:
I have an winform application that uses System.IO.StreamReader and Serializer.Deserialize to load some data from a file, if any error is detected in the file a new file should be written to the...
3
by: Glen Parker | last post by:
First things first: Postgresql 8.4.2 on Fedora Core 2 X86. Something seems to have happened to my pg_xlog and pg_clog directories after (I believe) a power outage. In the course of trying to...
1
by: ticmanis | last post by:
Hello, I'm having trouble getting MSIE 6.0 (running on XP SP2) to accept a cookie which works fine in both Firefox and wget. The web server is Boa 0.94.13 (a small embedded server) using PHP...
3
by: RadhikaG | last post by:
my dropdownlist_selectedindexchange method just refuses to get invoked when i switch from any value in the dropdown list to the default value. why??? how do i get it work for this as well?
12
by: Rainer Queck | last post by:
Hi NG, I have no idea why, but since a while a dataset refuses to write to a specific xml file. I get the error message "Der Zugriff auf den Pfad...
2
tpgames
by: tpgames | last post by:
Two days ago, MS office Word would type JP fonts, I thought. I didn't think I was using Works. Now, it won't type in JP. Jasc Paint shop pro 8, should type JP fonts because I am using XP, according...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.