Forums

This topic is locked

MM Insert Record & Update Cmd on same page?

Posted 01 Feb 2004 16:50:08
1
has voted
01 Feb 2004 16:50:08 paul stanley posted:
I am setting up a Website for a cottage rental property. If the customer wants to check whether the property is available for a given period, they complete the Availability Check form. They select a date from the Javascript date selector and then pick 3,7,14 or 21 nights stay.

When they press the Availability Check button, a search is done of the database table DateAvailable. This table consists of the following fields:

BookingDate (Date/Time)
Available Test (YES/NO)

Each record in the BookingDate fields is a day of the year ie, 01/02/2004 (UK format ddmmyyyy)

Each record in the AvailableTest field is either YES/NO. If set to YES then the property is booked. If NO then property is available.

My codes then searches the BookingDate and AvailableTest fields. It finds all the dates the user selected and then checks against the AvailableTest field. If all the AvailableTest records are available (set to NO) then a message comes back to the user "cottage available etc...". If any one of the AvailableTest records is set to YES, then a message comes back "cottage unavailable etc..."

If the property is available, the next stage is to get information from the customer, name, telephone, email etc., so I can take their request further. I then ask the customer to fill out the form to reserve the cottage for the selected dates. When they press the Submit button on the availabilityResults.asp page, this information gets stored in another database table: CottageReserve, which consists of the following fields:

EnquiryNo (AutoNumber)
forename (text)
surname (text)
tel (text)
mobile (text)
email (text)
partyNo (text)

This is done using the MM Insert Record Behavior.

At this stage you may want to try out the form. This can be found at: http:www.oldnickcottage.co.uk/availability.asp (site still in design so feel free to enter whatever you wish). Select a date range and then complete the form. When you've done, do it again and select the same date range. You will see that the cottage is still available to rent. If you've selected the same date range and filled out the personal information form, then it shouldn't be available to book.

So the user has selected certain dates and sent us their personal information. What I want to do now is to take the dates the user selected and make them all unavailable for booking (ie set them to YES) - booked.

What I want to happen is as soon as the user hits the submit button on the personal information form, the MM Insert Behavior inserts their personal information into the database (no problem with this). At the same time as the user submits the personal information form, I want the MM Update Command Behavior to activate and change the users selected dates to "booked" (YES). So the user has now reserved the selected dates and we will send them an email telling them that the property is theirs for the period they selected. If someone else comes along and selects the same dates, then the message will come back with property unavailable.

I need the MM Update Command Behavior to activate ONLY if the user completes the personal information form. If they don't complete the personal information form, then the Update Command Behavior does not trigger. I've encased my command Behavior with the following "If Then" statement, but to no avail:

If Request("paul" <> "" Then (run the Command)
where "paul" is the name of the Submit button

Can I have MM's Insert Record and Update Command Behaviors on the same page?

Regards

Paul (apologies for the long-windidness!!)





Replies

Replied 01 Feb 2004 17:45:59
01 Feb 2004 17:45:59 paul stanley replied:
Sorry about the length of my previous post. In a nutshell I want this Command Update to run when the user hits the "Submit" button on the availabilityResults page:

If Request("paul" <> "" Then

set Command1 = Server.CreateObject("ADODB.Command"
Command1.ActiveConnection = MM_pkson_STRING
Command1.CommandText = "UPDATE DateAvailable SET AvailableTest = 1 WHERE BookingDate >= #" + Replace(DoDateTime(userDate,1,2057), "'", "''" + "# and BookingDate <= #" + Replace(DoDateTime(varEndDate,1,2057), "'", "''" + "#"
Command1.CommandType = 1
Command1.CommandTimeout = 0
Command1.Prepared = true
Command1.Execute()

The Submit button is named "paul"

As a test I set

"If Request("paul" <> "" Then" to
"If Request("paul" = "" Then"

This runs the Command and updates the AvailabilityTest field to TRUE when the availabilityResults page is loaded. I don't need it to run when the page is loaded, only when the user completes the form. The code seems to do the right thing, only at the wrong time!!

Regards

Paul

ps. Final resting place for my Command Update code is under the MM Insert Record Behavior code (in fact I've placed it everywhere).



Reply to this topic