Go Back   DeveloperBarn Forums > Programming & Scripting > ASP Development

Sponsored Links

Discuss "logic problem" in the ASP Development forum.

ASP Development - Learn coding practices and tips to get the best out of your Active Server Pages (ASP). The Classic ASP forum is for ASP/VBScript and ASP/JScript applications.


Reply « Previous Thread | Next Thread »  
 
LinkBack Thread Tools Display Modes
  #1  
Old August 26th, 2008, 02:46 PM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default logic problem

Hi,

I have a page where user enters the details and enters credit card information and hits submits

whats its supposed to do is add the personal details in a table then get the id for the record and then do credit card processing and then update the table with the Id

here is my code

Code:
<%
 date1=FormatDateTime(Now(),vbGeneralDate)
 FName =Trim(Request.form("FName"))
 LName =Trim(Request.form("LName"))
 Institution =Trim(Request.form("Institution"))
 Position =Trim(Request.form("Position"))
 Address1 =Trim(Request.form("Add1"))
 Address2 =Trim(Request.form("Add2"))
 City =Trim(Request.form("City"))
 State =Trim(Request.form("State"))
 Zip =Trim(Request.form("Zip"))
 Country =Trim(Request.form("Country"))
 MemberPhone =Trim(Request.form("Phone"))
 FaxNumber =Trim(Request.form("FaxNumber"))
 Email =Trim(Request.form("Email"))
 EmergencyContact =Trim(Request.form("EmergencyContact"))
 EmergencyPhone =Trim(Request.form("EmergencyPhone"))
 CardType =Trim(Request.form("PaymentMethod"))
 CardNumber =Trim(Request.form("CreditCardNumber"))
 ExpirMonth =Trim(Request.form("ExpirMonth"))
 ExpirYear =Trim(Request.form("ExpirYear"))
 NameOnCard =Trim(Request.form("NameOnCard"))
 total= Request.form("totalcharge1")

 ExpirDate = ExpirMonth & ExpirYear
 CardNumberLength = Len(CardNumber)
 CardNumberShort= Mid(CardNumber,(CardNumberLength - 3), 4)

 strSQL ="select * from Registrations;"

 Set rsAdd = Server.CreateObject("ADODB.Recordset")
 With rsAdd
    .Source="Registrations"
    .CursorType = 2
    .LockType = 3
 End With
 rsAdd.Open strSQL, Conn
 rsAdd.AddNew
 rsAdd.Fields("First_Name") = Request.Form("FName")
 rsAdd.Fields("Last_Name") = Request.Form("LName")
 rsAdd.Fields("Institution") = Request.Form("Institution")
 rsAdd.Fields("Position") = Request.Form("Position")
 rsAdd.Fields("Address_1") = Request.Form("Add1")
 rsAdd.Fields("Address_2") = Request.Form("Add2")
 rsAdd.Fields("City") = Request.Form("City")
 rsAdd.Fields("State") = Request.Form("State")
 rsAdd.Fields("ZipCode") = Request.Form("Zip")
 rsAdd.Fields("Country") = Request.Form("Country")
 rsAdd.Fields("Phone") = Request.Form("Phone")
 rsAdd.Fields("Fax") = Request.Form("FaxNumber")
 rsAdd.Fields("Email") = Request.Form("Email")
 rsAdd.Fields("Payment_Method") = Request.Form("PaymentMethod")
 rsAdd.Fields("Credit_Card_Number") = CardNumberShort
 rsAdd.Fields("Expiration_Date") = ExpirDate
 rsAdd.Fields("Name_On_Card") = Request.Form("NameOnCard")
 rsAdd.Fields("Total_Charge") = total
 rsAdd.Fields("How_Recieved") = "Web"
 rsAdd.Fields("IP_Address") = userip
 rsAdd.Fields("Date_Recieved") = date1

 rsAdd.Update

 strid =  "SELECT Max(Id) as Newest from Registrations"
 Set RecSet = Conn.Execute(strid)
 ID = RecSet("Newest")
 RecSet.Close()

 Set RecSet = Nothing

	 If Err.Number <> 0 Then
		   FeedbackMessage = "<p>We're sorry, but there was a problem adding your information to the database.</p>"                        & vbNewLine _
		   & "<p>Error Number: " & Err.Number & "<br />" & vbNewLine _
		   & "Error Source: " & Err.Source & "<br />" &  vbNewLine _
           & "Error Description: " & Err.Description & "</p>"
           sDone = 0
     Else
    	   ParmList = "TRXTYPE=S&TENDER=C&zip=" + Zip + "&COMMENT1=on-line transaction"
           ParmList = ParmList + "&ACCT=" + CardNumber
           ParmList = ParmList + "&PWD=***********"
           ParmList = ParmList + "&USER=***********"
           ParmList = ParmList + "&VENDOR=**********"
           ParmList = ParmList + "&PARTNER=***"
           ParmList = ParmList + "&EXPDATE=" + ExpirDate
           ParmList = ParmList + "&AMT=" + cstr(total)

           set Client =Server.CreateObject("PFProCOMControl.PFProCOMControl.1")
           Context =Client.CreateContext("payflow.verisign.com", ***, **,"", 0, "", "")
           TransactionResult =Client.SubmitTransaction(Context, ParmList,Len(ParmList))
           Client.DestroyContext(Context)

           Do While Len(TransactionResult) <> 0
				If InStr(TransactionResult, "&") Then
					VarString = Left(TransactionResult,InStr(TransactionResult, "&" ) -1)
                Else
					VarString = TransactionResult
				End If


                Name = Left(VarString, InStr(VarString, "=")-1)
                Value = Right(VarString, Len(VarString) -(Len(Name)+1))

                If Name = "RESULT" Then
					 Result = Value
				Elseif Name = "PNREF" Then
					 PnRef = Value
				Elseif Name = "RESPMSG" Then
					 RespMsg = Value
                Elseif Name = "AUTHCODE" Then
					 AuthCode = Value
				End If

				If Len(TransactionResult) <> Len(VarString) Then
					TransactionResult = Right(TransactionResult,Len(TransactionResult) - (Len(VarString)+1))
				Else
					TransactionResult = ""
				End If
           Loop

          strinsert= "UPDATE Registrations SET PNREF = '" &  PnRef & "', Result = '" & Result & "', AuthCode = '" & AuthCode & "', RespMsg = '" & RespMsg & "' WHERE  (Id = " & ID & ")"


		  On Error Resume Next

			Conn.Execute(strinsert)

            Conn.Close
            Set Conn = Nothing

         If Err.Number <> 0 Then
                FeedbackMessage = "<p>We're sorry, but there was  a problem adding your information to the  database.</p>" & vbNewLine _
                & "<p>Error Number: " & Err.Number & "<br />" & vbNewLine _
                & "Error Source: " & Err.Source & "<br />" &  vbNewLine _
                & "Error Description: " & Err.Description & "</p>"
                Done = 0

         Else

               If (Result = 0) Then
           %>
SHow me
<%
Else
	Response.Redirect("decline.asp)

                    End If

           End If

		      Err.Clear
               On Error Goto 0

  End If
        
			      Err.Clear
               On Error Goto 0

 

%>
my biggest problem is if there are 2 people filling the form at same time

say John doe and jason smith

what happens is both records are added in the table but when the credit card is processed
jason smith verification number will be attached to john doe's number
and jason smith doesnt has a verification number can someone tell me how i can prevent is do i need to do add transaction code or is there a different way

thanks for all the help

todd
Reply With Quote
Sponsored Links
  #2  
Old August 26th, 2008, 03:23 PM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

Your code will have problems in a multi-user environment. Always assume that a series of SQL statement can be interrupted and not execute in the order you expect. Problems like can usually be solved with a stored procedure -- what DB are you using?
__________________
Wolffy
------------------------
Opinions expressed are my own and do not necessity reflect those of any sane person. Any code provided is intended to be an example and is provided AS IS. Rework for your specific environment may be required. Void where prohibited by law. Not valid in California. Your mileage may vary.
Reply With Quote
  #3  
Old August 26th, 2008, 03:36 PM
Barn Frequenter

 
Join Date: Mar 2008
Posts: 197
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Power: 1
todd2006 is an unknown quantity at this point
Default

sql server
Reply With Quote
  #4  
Old August 26th, 2008, 03:48 PM
Wolffy's Avatar
Slaprentice of Wolves

 
Join Date: Mar 2008
Location: Peoria, IL
Posts: 175
Thanks: 3
Thanked 24 Times in 21 Posts
Rep Power: 1
Wolffy is on a distinguished road

Awards Showcase
Microsoft .Net 
Total Awards: 1

Default

Cool. Store Procedure to the rescue. The problem you face here is that Joe's record could be inserted, then Bob's record and the you do the Select MAX and get Bob's ID number. Not cool. So, put the INSERT into a Stored Procedure. Here's a small example that should be easy to build on:
Code:
CREATE PROCEDURE InsertEmployee
(@LastName NVARCHAR(20),
@FirstName NVARCHAR(10),
@EmployeeID INT OUTPUT)
AS
INSERT INTO Registrations(Fname,Lname)
VALUES(@FirstName,@LastName)
SET @EmployeeID = SCOPE_IDENTITY() 
Note the use of the Output Parameter. For a complete look at this look here Page 4 - Using T-SQL Stored Procedures with ASP.NET 2.0
and also here http://support.microsoft.com/kb/164485 for into on doing this in Classic ASP

Last edited by Wolffy; August 26th, 2008 at 03:52 PM.
Reply With Quote
Reply

  DeveloperBarn Forums > Programming & Scripting > ASP Development

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT -4. The time now is 06:41 PM.



Content Relevant URLs by vBSEO 3.2.0