473,398 Members | 2,812 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,398 software developers and data experts.

ASP form page

1
Hi everyone

I'm learning asp, and i downloaded this script to teach me how to post form data from a webpage to an access database. I put it on the server so i could make sure that it worked, and everything was fine, so i changed the variable names (the names of the form elements, and the names of the rows in access) so that it would be more correct to what i am using it for. Now once I did that, it gave me an error on line 24 which was the SQL insert command. I didnt change that, and I cannot figure out why just changing the names would cause this problem.

This is the form that works:
Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <title>Test ASP to database and reporting</title>
  3. <body bgcolor="#bae8f9">
  4. <img src="itform.jpg" border=0>
  5. <script language="JavaScript"><!--
  6. function stamp() {
  7.     document.form.email.value = new Date();
  8. }
  9. //--></script>
  10.  
  11. <form action="form_ac.asp" method="post" name="form" onSubmit="stamp()">
  12. <table border=0>
  13. <tr>
  14. <td>
  15. Station:
  16. </td>
  17. <td>
  18. <input type="text" name="name"><br>
  19. </td>
  20. </tr>
  21. <tr>
  22. <td>
  23. <input type="hidden" name="email">
  24. <input type="hidden" name="country" value="No">
  25. Problem:
  26. </td>
  27. <td>
  28. <textarea name="comments" cols="20" rows="5"></textarea><br>
  29. </td>
  30. </tr>
  31. <tr>
  32. <td>
  33. <input type="submit" value="Submit">
  34. </td>
  35. <td>
  36. <input type="reset" value="Reset">
  37. </td>
  38. </tr>
  39. </table>
  40. </form>
  41. </body>
  42. </html>
  43.  
and this is the asp page that it goes through to send it to the database:
Expand|Select|Wrap|Line Numbers
  1. <%
  2. ' Declaring variables
  3. Dim name, email, country, comments, data_source, con, sql_insert
  4.  
  5. ' A Function to check if some field entered by user is empty
  6. Function ChkString(string)
  7. If string = "" Then string = " "
  8. ChkString = Replace(string, "'", "''")
  9. End Function
  10.  
  11. ' Receiving values from Form
  12. name = ChkString(Request.Form("name"))
  13. email = ChkString(Request.Form("email"))
  14. country = ChkString(Request.Form("country"))
  15. comments = ChkString(Request.Form("comments"))
  16. data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ 
  17. Server.MapPath("form.mdb")
  18. sql_insert = "insert into users (name, email, country, comments) values ('" & _
  19. name & "', '" & email & "', '" & country & "', '" & comments & "')"
  20.  
  21. ' Creating Connection Object and opening the database
  22. Set con = Server.CreateObject("ADODB.Connection")
  23. con.Open data_source
  24. con.Execute sql_insert
  25.  
  26. ' Done. Close the connection
  27. con.Close
  28. Set con = Nothing
  29.  
  30. Response.Write "Your request has been submitted. Thank you."
  31.  
  32. Response.AddHeader "Refresh", "2;URL=form.htm" 
  33. %>
  34.  
that one works, but all the names are country email name and comments. This isint really a problem, but I would like to know what is wrong, so i can add other elements to the form, and change their names.
Here is the one i changed, and doesnt work:
Expand|Select|Wrap|Line Numbers
  1.  <html>
  2. <title>Test ASP to database and reporting</title>
  3. <body>
  4.  
  5. <script language="JavaScript"><!--
  6. function stamp() {
  7.     document.form.datetime.value = new Date();
  8. }
  9. //--></script>
  10.  
  11. Information to be entered to access
  12. <form action="form_ac.asp" method="post" name="form" onSubmit="stamp()">
  13. Station : <input type="text" name="station"><br>
  14. <input type="hidden" name="datetime"><br>
  15. Problem : <textarea name="problem" cols="20" rows="5"></textarea><br>
  16. <input type="hidden" name="fixed" value="No">
  17. <input type="submit" value="Submit"><input type="reset" value="Reset">
  18. </form>
  19. </body>
  20. </html>
  21.  
and here is the changed asp file
Expand|Select|Wrap|Line Numbers
  1. <%
  2. ' Declaring variables
  3. Dim station, datetime, problem, fixed, data_source, con, sql_insert
  4.  
  5. ' A Function to check if some field entered by user is empty
  6. Function ChkString(string)
  7. If string = "" Then string = " "
  8. ChkString = Replace(string, "'", "''")
  9. End Function
  10.  
  11. ' Receiving values from Form
  12. station = ChkString(Request.Form("station"))
  13. datetime = ChkString(Request.Form("datetime"))
  14. problem = ChkString(Request.Form("problem"))
  15. fixed = ChkString(Request.Form("fixed"))
  16. data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _ 
  17. Server.MapPath("form.mdb")
  18. sql_insert = "insert into users (station, datetime, problem, fixed) values ('" & _
  19. station & "', '" & datetime & "', '" & problem & "', '" & fixed & "')"
  20.  
  21. ' Creating Connection Object and opening the database
  22. Set con = Server.CreateObject("ADODB.Connection")
  23. con.Open data_source
  24. con.Execute sql_insert
  25.  
  26. ' Done. Close the connection
  27. con.Close
  28. Set con = Nothing
  29. %>
  30.  
I went through both databases, and all of the fields are set to text, and everything is the same case, no misspellings or anything.
Please help, this was intended for me to learn from, and it doesnt make any sense to me why something so simple wont work properly.
Thank you,
Dan
Apr 18 '07 #1
1 2533
Choose an other name for the DATETIME variable because it is a reserved ACCESS word.

http://www.bairdgroup.com/reservedwords.cfm

In my opinion it is good practice to prefix variable names with their "type" (Although ASP-script is not strongly typed). E.g. dtDateTime, strName, intCounter, objRecordSet etc.
Apr 19 '07 #2

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

Similar topics

1
by: Newbie | last post by:
OK, this may be impossible since I'm using 3rd party shopping cart ASP software, but I've been able to finagle a lot of other stuff I thought wouldn't work, so here we go: I'm using a form in...
10
by: Noozer | last post by:
Below is some ASP, HTML and javascript. It is part of a page used to maintain a small database. This code did work at one time, but has since stopped. For some reason the data on my form is not...
0
by: Pat Patterson | last post by:
I'm having serious issues with a page I'm developing. I just need some simple help, and was hoping someone might be able to help me out in here. I have a form, that consists of 3 pages of...
11
by: Jozef | last post by:
I have some old code that I use from the Access 95 Developers handbook. The code works very well, with the exception that it doesn't seem to recognize wide screens, and sizes tab controls so that...
0
by: 42 | last post by:
I implemented a simple class inherited from Page to create a page template. It simply wraps some trivial html around the inherited page, and puts the inherited page into a form. The problem I...
9
by: eswanson | last post by:
I have a web page I need to post a file plus some other fields to it. How can I do this from a asp.net page. I know I can send individual fields to the other page, but how do I send a file to the...
4
by: Alex Maghen | last post by:
I have a master page which contains a general page framework and also contains a <form runat=server> around most of the content of the page. Inside that <form> tag is a ContentPlaceholder. I...
16
by: whyyyy | last post by:
The script below works fine if the form is filled out and submitted. But a (blank) e-mail is sent whenever the page loads, even when the form is not submitted. I would like to receive the e-mail...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
4
by: pbd22 | last post by:
hi. could somebody tell me, when uploading a file, i know the form where the upload component is must have enctype=multipart/form-data but, is the same true for the form with the server code to...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.