Wrox Programmer Forums
|
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 10th, 2003, 12:18 PM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to kkbigal
Default ASP code to update database on submitting form?

Hi all, I'm relatively new to ASP and web development and I've got a bit of problem.
I have a page with a form that submits details to an Access database. I have added an ADO command to increase a value in the database. However, I want this increase to only occur when I submit the form and I already have something occupying the ACTION form tag. At the moment, I've tried adding the function name to a button OnClick (function called test: OnClick="<%test%>" ) Now the code actually runs and the database gets updated but it happens when the page is loaded and I want it to happen when the form is submitted.

Any ideas? :)

 
Old July 10th, 2003, 02:59 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You are mixing two concepts: ASP code runs at the server while JavaScript like OnClick runs at the client. Your current code runs fine (well, at least it runs) because just before the page is sent to the browser, all ASP code is executed at the server. That's why the test method runs when you load the page.

So, they only way to access ASP code is at the server, after you have submitted the data to the server, using GET or POST.

Usually, you'll want to do something like this:

1. Add a client side handler that submits the form (like a button click, or MyForm.submit() from some JavaScript)

2. At the server, check whether the page has been submitted (that is, Request.Form("btnMyButton") has a value, for example)

3. If the page has been resubmitted, do your database insert based on the form values.

I am not sure what you mean with "I already have something occupying the ACTION form tag" Are you saying that you don't want to post to the page currently set in the action attribute?

If that's the case, you have a few options:

1. Define multiple forms on the page. Each form can have its own submit methods and action attributes.

2. Submit to another (or hidden) frame

3. Use some JavaScript to open a new page that submits a form.

HtH

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old July 11th, 2003, 03:31 AM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to kkbigal
Default

Thanks for the reply :) I had already considered using javascript to open a new page to submit but was wondering if there was another way. I'll probably end up doing that.

 
Old July 14th, 2003, 05:55 AM
Registered User
 
Join Date: Jul 2003
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to kkbigal
Default

woohoo!! I spent another couple of days banging my head against a brick wall trying to figure a way of sending the variable to another page with javascript. And as I was sipping on a much needed fizzy beverage, the answer came to me in the form of the SQL COUNT function :) In the database itself I was already calculating the number of people booked on to a specific course using the DCOUNT function. Now I've recreated the same calculation on the web page to count up the number of records associated with the course the user is looking at and written a script to redirect them if the current places booked is greater or equal to max places. And it works....I think I need to go lie down :D






Similar Threads
Thread Thread Starter Forum Replies Last Post
code doesn't update database Lesviper Beginning VB 6 1 February 7th, 2005 10:18 AM
Submitting a form to a database nvillare Classic ASP Basics 2 January 27th, 2005 06:38 PM
Submitting a form YuliaKupina Classic ASP Basics 3 June 24th, 2004 01:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.