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: -
<html>
-
<title>Test ASP to database and reporting</title>
-
<body bgcolor="#bae8f9">
-
<img src="itform.jpg" border=0>
-
<script language="JavaScript"><!--
-
function stamp() {
-
document.form.email.value = new Date();
-
}
-
//--></script>
-
-
<form action="form_ac.asp" method="post" name="form" onSubmit="stamp()">
-
<table border=0>
-
<tr>
-
<td>
-
Station:
-
</td>
-
<td>
-
<input type="text" name="name"><br>
-
</td>
-
</tr>
-
<tr>
-
<td>
-
<input type="hidden" name="email">
-
<input type="hidden" name="country" value="No">
-
Problem:
-
</td>
-
<td>
-
<textarea name="comments" cols="20" rows="5"></textarea><br>
-
</td>
-
</tr>
-
<tr>
-
<td>
-
<input type="submit" value="Submit">
-
</td>
-
<td>
-
<input type="reset" value="Reset">
-
</td>
-
</tr>
-
</table>
-
</form>
-
</body>
-
</html>
-
and this is the asp page that it goes through to send it to the database: -
<%
-
' Declaring variables
-
Dim name, email, country, comments, data_source, con, sql_insert
-
-
' A Function to check if some field entered by user is empty
-
Function ChkString(string)
-
If string = "" Then string = " "
-
ChkString = Replace(string, "'", "''")
-
End Function
-
-
' Receiving values from Form
-
name = ChkString(Request.Form("name"))
-
email = ChkString(Request.Form("email"))
-
country = ChkString(Request.Form("country"))
-
comments = ChkString(Request.Form("comments"))
-
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
-
Server.MapPath("form.mdb")
-
sql_insert = "insert into users (name, email, country, comments) values ('" & _
-
name & "', '" & email & "', '" & country & "', '" & comments & "')"
-
-
' Creating Connection Object and opening the database
-
Set con = Server.CreateObject("ADODB.Connection")
-
con.Open data_source
-
con.Execute sql_insert
-
-
' Done. Close the connection
-
con.Close
-
Set con = Nothing
-
-
Response.Write "Your request has been submitted. Thank you."
-
-
Response.AddHeader "Refresh", "2;URL=form.htm"
-
%>
-
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: -
<html>
-
<title>Test ASP to database and reporting</title>
-
<body>
-
-
<script language="JavaScript"><!--
-
function stamp() {
-
document.form.datetime.value = new Date();
-
}
-
//--></script>
-
-
Information to be entered to access
-
<form action="form_ac.asp" method="post" name="form" onSubmit="stamp()">
-
Station : <input type="text" name="station"><br>
-
<input type="hidden" name="datetime"><br>
-
Problem : <textarea name="problem" cols="20" rows="5"></textarea><br>
-
<input type="hidden" name="fixed" value="No">
-
<input type="submit" value="Submit"><input type="reset" value="Reset">
-
</form>
-
</body>
-
</html>
-
and here is the changed asp file -
<%
-
' Declaring variables
-
Dim station, datetime, problem, fixed, data_source, con, sql_insert
-
-
' A Function to check if some field entered by user is empty
-
Function ChkString(string)
-
If string = "" Then string = " "
-
ChkString = Replace(string, "'", "''")
-
End Function
-
-
' Receiving values from Form
-
station = ChkString(Request.Form("station"))
-
datetime = ChkString(Request.Form("datetime"))
-
problem = ChkString(Request.Form("problem"))
-
fixed = ChkString(Request.Form("fixed"))
-
data_source = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & _
-
Server.MapPath("form.mdb")
-
sql_insert = "insert into users (station, datetime, problem, fixed) values ('" & _
-
station & "', '" & datetime & "', '" & problem & "', '" & fixed & "')"
-
-
' Creating Connection Object and opening the database
-
Set con = Server.CreateObject("ADODB.Connection")
-
con.Open data_source
-
con.Execute sql_insert
-
-
' Done. Close the connection
-
con.Close
-
Set con = Nothing
-
%>
-
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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
|
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...
|
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...
|
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,...
|
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...
|
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,...
|
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...
|
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...
|
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...
| |