Ask a Question related to Coldfusion Database Access, Design and Development.
-
ms526 #1
Inserting data from a form to an MS access database
I'm new to coldfusion, and have run into a problem when trying to insert data
from a basic HTML form into an MS Access database.
The problem is the primary key. When I remove the primary key from the
database, it works fine, but I need it to have one.
I'm not sure how to add the primary key as an autonumber.
I'm using Dreamweaver MX 2004 with a test setup of CF MX7 and IIS 5.1 on
Windows XP Pro
Code is below. The first page is the Form, and the second is the page that
processes the form and adds it to the databse
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="signup2.cfm" method="post" name="Signup" id="Signup">
<p>
<input name="username" type="text" id="username">
Name</p>
<p>
<input name="Age" type="text" id="Age">
Age
</p>
<p>
<input name="email" type="text" id="email">
E-mail</p>
<p>
<input name="Location" type="text" id="Location">Location</p>
<p>
<input name="ID" type="hidden" id="ID">
</p>
<p>
<input name="submit" type="submit">
</p>
<p> </p>
</form>
</body>
</html>
<cfquery name="adduser" datasource="CFtest">
INSERT INTO signup
VALUES ('#Form.username#', '#Form.Age#',
'#Form.Location#', '#Form.email#', #Form.ID#)
</cfquery>
<html>
<head>
<title>You have added <cfoutput>#Form.username# to the
database!</cfoutput></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
You have successfully added <cfoutput>#Form.username#</cfoutput> to the
database.
</body>
</html>
ms526 Guest
-
Copying data from one Access database to another
I am working on a project where I need to get data from an Access database uploaded daily by my client and copy fields from various tables into... -
Trouble inserting data in database
I use DW 2004, XP with sp2, and Access 2003. Im planning to make a site that is possible to log in and update news from the web. So I have made a... -
Inserting form info into access problem
I am developing three different surveys which are the same topic - different view points. I have 2 forms working and going into the tables... -
Inserting data from text file into database
Is it possible to write a script in an ASP page that reads a comma delimited text file and inserts the data row by row into an Access db? Each comma... -
Inserting an Excel chart in an Access form.
The process described here must be completely automated. I'm building an Access form to show pricing evolution (price variance based on quantity... -
paross1 #2
Re: Inserting data from a form to an MS access database
Do you need to know what the primary key value is before you do the insert? Do
you need to know what it is after? You should let Access create the value as an
AUTONUMBER field, which means that you would insert all of the fields
<i>except</i> the primary key (ID) field. If you needed the ID value, you would
have to immediately query to get it (select max(id)...), and probably use
cftransaction to ensure that your insert and select were in the same database
transaction, otherwise on a busy site, you might get the wrong ID value. (SQL
Server and Oracle have better methods for obtaining the last ID values, so when
using Access it is kind of a kludge.)
Phil
paross1 Guest
-
Dan Bracuk #3
Re: Inserting data from a form to an MS access database
Following up on Phil's comment's lets assume you don't need to know the primary
key value before you do your insert. Change this:
INSERT INTO signup
VALUES ('#Form.username#', '#Form.Age#',
'#Form.Location#', '#Form.email#', #Form.ID#)
to this, (but with your actual field names)
INSERT INTO signup
(username, age, location, email)
VALUES ('#Form.username#', '#Form.Age#',
'#Form.Location#', '#Form.email#')
Dan Bracuk Guest
-
ms526 #4
Re: Inserting data from a form to an MS access database
ok thanks for your help guys. Dan's suggestion worked perfectly.
ms526 Guest



Reply With Quote

