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 2539
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 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...
|
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...
|
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...
|
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...
|
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...
| |
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...
|
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......
|
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")
|
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...
|
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.
|
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...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |