Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

ASP vb script coding problem

Options
  • 09-04-2008 10:00am
    #1
    Closed Accounts Posts: 41


    Hey,

    I have a form with two radio buttons that when one is clicked will bring up another form. Each of these forms when submitted trigger a different stored procedure each in my SQL server database. they both insert into the same table then each into anther table each too. the problem i am having with this is that the first form is working and one of the others then the third form is only half working.

    What i want to do is use an if statement in my asp code so that only one of the stored proc's is fired. this is my attempt so far.
    <%
    ' *** Insert Record: set variables
    if request.form("choose") then
    If (CStr(Request("MM_insert")) = "form1") Then
      MM_editConnection = MM_B00007547_STRING
      MM_editTable = "dbo.Customer"
      MM_editRedirectUrl = "Individual_Register.asp"
      MM_fieldsStr  = "address|value|town|value|county|value|phone_no|value"
      MM_columnsStr = "Address|',none,''|Town|',none,''|County|',none,''|Phone_no|',none,''"
      ' create the MM_fields and MM_columns arrays
      MM_fields = Split(MM_fieldsStr, "|")
      MM_columns = Split(MM_columnsStr, "|")
      
      ' set the form values
      For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
        MM_fields(MM_i+1) = CStr(Request.Form(MM_fields(MM_i)))
      Next
      ' append the query string to the redirect URL
      If (MM_editRedirectUrl <> "" And Request.QueryString <> "") Then
        If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString <> "") Then
          MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
        Else
          MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
        End If
      End If
    Dim MM_tableValues
    Dim MM_dbValues
    else if
    ' *** Insert Record: construct a sql insert statement and execute it
    (CStr(Request("MM_insert")) <> "") Then
      ' create the sql insert statement
      MM_tableValues = ""
      MM_dbValues = ""
      For MM_i = LBound(MM_fields) To UBound(MM_fields) Step 2
        MM_formVal = MM_fields(MM_i+1)
        MM_typeArray = Split(MM_columns(MM_i+1),",")
        MM_delim = MM_typeArray(0)
        If (MM_delim = "none") Then MM_delim = ""
        MM_altVal = MM_typeArray(1)
        If (MM_altVal = "none") Then MM_altVal = ""
        MM_emptyVal = MM_typeArray(2)
        If (MM_emptyVal = "none") Then MM_emptyVal = ""
        If (MM_formVal = "") Then
          MM_formVal = MM_emptyVal
        Else
          If (MM_altVal <> "") Then
            MM_formVal = MM_altVal
          ElseIf (MM_delim = "'") Then  ' escape quotes
            MM_formVal = "'" & Replace(MM_formVal,"'","''") & "'"
          Else
            MM_formVal = MM_delim + MM_formVal + MM_delim
          End If
        End If
        If (MM_i <> LBound(MM_fields)) Then
          MM_tableValues = MM_tableValues & ","
          MM_dbValues = MM_dbValues & ","
        End If
        MM_tableValues = MM_tableValues & MM_columns(MM_i)
        MM_dbValues = MM_dbValues & MM_formVal
      Next
      MM_editQuery = "insert into " & MM_editTable & " (" & MM_tableValues & ") values (" & MM_dbValues & ")"
      If (Not MM_abortEdit) Then
        ' execute the insert
        Set MM_editCmd = Server.CreateObject("ADODB.Command")
        MM_editCmd.ActiveConnection = MM_editConnection
        MM_editCmd.CommandText = MM_editQuery
        MM_editCmd.Execute
        MM_editCmd.ActiveConnection.Close
        If (MM_editRedirectUrl <> "") Then
          Response.Redirect(MM_editRedirectUrl)
        End If
      End If
    End If %>
    

    as you can see i dont know if this is the right place or syntax for my if statement?

    "choose" is the name of my first form with the radio buttons, so really what ive been trying to do is assign the if statement so that if the 1st radio button is checked then the first form is submitted and the same if the second radio button is checked?

    any inkling of help will help greatly.


Comments

  • Registered Users Posts: 706 ✭✭✭DJB


    Trying to customise DW code is not going to be pretty. Especially if you use the DW functions again, it may delete your code. It would be easy to do with a bit of custom code. Statement would look like:

    SELECT CASE request("chosen")

    CASE "option1"
    sSQL = "UPDATE blah blah blah table1" 'whatever your sql code is, put it here

    CASE "option2"
    sSQL = "UPDATE blah blah blah table2" 'whatever your sql code is, put it here

    CASE "option3"
    sSQL = "UPDATE blah blah blah table3" 'whatever your sql code is, put it here

    END SELECT

    CALL ExecuteSQL(sSQL,sConn) 'I have a function that handles execution of sql

    That might put you on the right path.

    Rgds, Dave


Advertisement