473,581 Members | 2,786 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP form page

1 New Member
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 2539
Arnold Schuur
36 New Member
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
7426
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 which users enter numbers to be calculated into a square footage cost. Upon submitting, the results page uses ASP to give the total and the chance to...
10
2889
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 being passed to the page specified in the Action property of the form. This is on a Windows 2000 Pro PC. I copied the code to another server...
0
1971
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 fields. I'd like to create a page in which all of this is stored as you move along as hidden variables, until the end, when the user submits. I can't...
11
18823
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 they are too big and wind up covering up some of the fields on the main form. Is there any good code out there that works in a similar fashion...
0
1876
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 have run into is that the emitted html at the end of the process is slightly different and doesn't work. Please don't be put off by all the source...
9
3134
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 other page, or is there something else like a stream which will be like a file. I am attempting to get a way from writing out a file and then...
4
13316
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 then create an ASPX which is tied to that MasterPage and in it a put a bunch of form fields and an <asp:Button />. When I try to run the page, I get......
16
3138
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 only when the form is submitted <%@LANGUAGE="VBSCRIPT"%> <% Set MyMail=CreateObject("CDO.Message")
27
4711
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 appears that the data goes straight to the processing page, rather than the javascript seeing if data is missing and popping up an alert. I thought it...
4
3136
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 handle the upload? thanks.
0
7882
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7808
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
6564
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5683
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5366
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3809
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3835
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2309
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1410
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.