Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old September 4th, 2003, 12:29 PM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to blink
Default CheckBox Insert Problem

Hi Guys,

This is my first post here, so bear with me.

The Problem is this: I have a MS Access DB with several collums, 3 of which are checkboxes. I have no problems getting them to insert if I go straight from form to DB, but this particular application requires me to do a step by step format because some fields depend on previous fields. On the final page before the insert, all of the data they entered is displayed for their approval. if they click submit the data insterts into the DB. This is working fine as all of the data is being entered except the checkboxes.

I use some IF statements to get the checked value of the checkboxes and I know these are working becuase I physically see that they are responding right. Only the insert is faulty. below is the code that constructs the SQL and the checkbox code. Keep in mind that is is Dreamweaver's code, so I'd like to stick with this format. Thanks for any help you guys can give and for bearing through this long post.

  #2 (permalink)  
Old September 4th, 2003, 12:34 PM
Registered User
 
Join Date: Sep 2003
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to blink
Default

----------------SQL CODE---------------------------------


<%@LANGUAGE="VBSCRIPT"%>

<%
' *** Edit Operations: declare variables

Dim MM_editAction
Dim MM_abortEdit
Dim MM_editQuery
Dim MM_editCmd

Dim MM_editConnection
Dim MM_editTable
Dim MM_editRedirectUrl
Dim MM_editColumn
Dim MM_recordId

Dim MM_fieldsStr
Dim MM_columnsStr
Dim MM_fields
Dim MM_columns
Dim MM_typeArray
Dim MM_formVal
Dim MM_delim
Dim MM_altVal
Dim MM_emptyVal
Dim MM_i

MM_editAction = CStr(Request.ServerVariables("SCRIPT_NAME"))
If (Request.QueryString <> "") Then
  MM_editAction = MM_editAction & "?" & Request.QueryString
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%>
<%
' *** Insert Record: set variables

If (CStr(Request("MM_insert")) = "form1") Then

  MM_editConnection = MM_D_STRING
  MM_editTable = "TBL_Main"
  MM_editRedirectUrl = "view1.asp"
  MM_fieldsStr = "TDNo|value|CCC|value|Code|value|Title|value|Prepa redBy|value|RequestedBy|value|Due|value|Delivered| value|Classified|value|DocCntrlNo|value|Archived|v alue|QTA|value|Comments|value"
  MM_columnsStr = "TDNo|',none,''|CCC|',none,''|Code|',none,''|Title |',none,''|PreparedBy|',none,''|RequestedBy|',none ,''|Due|#,none,NULL|Delivered|#,none,NULL|Classifi ed|none,1,0|DocCtlNo|',none,''|Archived|none,1,0|Q TA_Y|none,1,0|Comments|',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

End If
%>
<%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (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
%>

-------------------CHECKBOXES---------------------

<td class="body2"> <div align="right">Classified/Sensative:</div></td>
                          <td class="bodycopy"> <% Dim strClassified
                             Dim strChecked
                         Dim strClassifiedValue
                         IF Request.Form("Classified")="Yes" THEN
                             strClassified = "Yes"
                         strChecked = "checked"
                         strClassifiedValue = 1
                         ELSE
                         strClassified = "No"
                         strChecked = ""
                         strClassifiedValue = 0
                         END IF%>
<%=strClassified%> <input name="Classified" type="checkbox" id="Classified" disabled="true" <%=strChecked%> value="<%=strClassifiedValue%>">

                          </td>
                          <td colspan="2" class="body2"> <div align="left">
                              <% If Request.Form("Classified") = "Yes" Then %>
                              Document Control No. : </div></td>
                          <td class="bodycopy"><span class="bodycopy"><%=Request.Form("DocCntrlNo")%></span> <% End If %>
                                          <% Dim strDocCntrlNo IF Request.Form("Classified")="Yes" THEN
                        strDocCntrlNo = Request.Form("DocCntrlNo")
                     ELSE
                     strDocCntrlNo = "N/A"
                     END IF
                     %>
 <input name="DocCntrlNo" type="hidden" id="DocCntrlNo2" value="<%=strDocCntrlNo%>"></td>
                        </tr>
                        <tr>
                          <td class="body2"><div align="right">Archived:</div></td>
                          <td class="bodycopy"> <%
                          Dim strArchived
                              Dim strArchivedValue
                             IF Request.Form("Archived")="Yes" THEN
                         strArchived = "Yes"
                             strChecked = "checked"
                         strArchivedValue = 1
                         ELSE
                         strArchived = "No"
                         strChecked = ""
                         strArchivedValue = 0
                         END IF
                           %>
 <%=strArchived%> <input name="Archived" type="checkbox" id="Archived" disabled="true" <%=strChecked%> value="<%=strArchivedValue%>">
                          </td>
                          <td colspan="2" class="body2">&nbsp;</td>
                          <td class="bodycopy">&nbsp;</td>
                        </tr>
                        <tr>
                          <td class="body2"><div align="right">Quick Turn Around:</div></td>
                          <td class="bodycopy"> <%
                         Dim strQTA
                         Dim strQTAValue
                         IF Request.Form("QTA")="Yes" THEN
                         strQTA = "Yes"
                         strChecked = "checked"
                         strQTAValue = 1
                         ELSE
                         strQTA = "No"
                         strChecked = ""
                         strQTAValue = 0
                         END IF
                        %>
<%=strQTA%> <input name="QTA" type="checkbox" id="QTA" disabled="true" <%=strChecked%> value="<%=strQTAValue%>">
                          </td>



Similar Threads
Thread Thread Starter Forum Replies Last Post
insert checkbox in datagrid kau_shuk VS.NET 2002/2003 0 November 2nd, 2006 09:32 AM
"Insert into - checkbox value" Form connection jb_norman PHP Databases 0 July 30th, 2006 06:26 AM
insert multiple checkbox values in to database muthumari_p2003@yahoo.com Pro JSP 0 March 29th, 2006 08:23 AM
How to insert checkbox values to mysql using php method PHP Databases 0 February 21st, 2006 10:47 PM





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