Get ready for BLACK FRIDAY shopping starting in

Forums

This topic is locked

Combine 5 radiobuttons and inserting in db?

Posted 20 Dec 2005 15:48:02
1
has voted
20 Dec 2005 15:48:02 Henrik Sandeberg posted:
I have making an survey for my company, they want radiobuttons (i hate radiobuttons...). How do i use them to insert to a db. If i have 5 radiobuttons (in 27 questions) Im using IIS 5 and an Access 2000 db. i always get a message that i have Duplicate output destination 'Q4'. Ican post the code below. I dont post all the code, cause its about 800 rows.......

<pre id=code><font face=courier size=2 id=code>
&lt;%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%&gt;
&lt;!--#include file="Connections/enkat.asp" --&gt;
&lt;%
' *** 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 &lt;&gt; "" Then
MM_editAction = MM_editAction & "?" & Server.HTMLEncode(Request.QueryString)
End If

' boolean to abort record edit
MM_abortEdit = false

' query string to execute
MM_editQuery = ""
%&gt;
&lt;%
' *** Insert Record: set variables

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

MM_editConnection = MM_enkat_STRING
MM_editTable = "Survey"
MM_editRedirectUrl = ""
MM_fieldsStr = "Manellerkvinna|value|n|value|hurbordu|value|q4|value|q4|value|q4|value|q4|value|q4|value|q5|value|q5|value|q5|value|q5|value|q5|value|q6|value|q7|value|q8|value|q9|value|q10|value|q11|value|q12|value|q13|value|q14|value|q15|value|q16|value|q17|value|q18|value|q19|value|q20|value|q21|value|q22|value|q23|value|q24|value|q25a|value|q25b|value|q25b|value|q25b|value|q25b|value|q25b|value|q26|value|q27|value"
MM_columnsStr = "Q1|none,none,NULL|Q2|none,none,NULL|Q3|',none,''|Q4|none,Yes,No|Q4|none,Yes,No|Q4|none,Yes,No|Q4|none,Yes,No|Q4|none,Yes,No|Q5|none,Yes,No|Q5|none,Yes,No|Q5|none,1,0|Q5|none,1,0|Q5|none,1,0|Q6|none,none,NULL|Q7|none,none,NULL|Q8|none,none,NULL|Q9|none,none,NULL|Q10|none,none,NULL|Q11|none,none,NULL|Q12|none,none,NULL|Q13|none,none,NULL|Q14|none,none,NULL|Q15|none,none,NULL|Q16|none,none,NULL|Q17|none,none,NULL|Q18|none,none,NULL|Q19|none,none,NULL|Q20|none,none,NULL|Q21|none,none,NULL|Q22|none,none,NULL|Q23|none,none,NULL|Q24|none,none,NULL|Q25A|none,none,NULL|Q25B|none,1,0|Q25B|none,1,0|Q25B|none,1,0|Q25B|none,1,0|Q25B|none,1,0|Q26|none,none,NULL|Q27|',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 &lt;&gt; "" And Request.QueryString &lt;&gt; "" Then
If (InStr(1, MM_editRedirectUrl, "?", vbTextCompare) = 0 And Request.QueryString &lt;&gt; "" Then
MM_editRedirectUrl = MM_editRedirectUrl & "?" & Request.QueryString
Else
MM_editRedirectUrl = MM_editRedirectUrl & "&" & Request.QueryString
End If
End If

End If
%&gt;
&lt;%
' *** Insert Record: construct a sql insert statement and execute it

Dim MM_tableValues
Dim MM_dbValues

If (CStr(Request("MM_insert") &lt;&gt; "" 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 &lt;&gt; "" 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 &lt;&gt; 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 &lt;&gt; "" Then
Response.Redirect(MM_editRedirectUrl)
End If
End If

End If
%&gt;
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Tyck till - Registrering&lt;/title&gt;
&lt;link href="include/include.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;span class="verdanastor"&gt;Tyck till - Registrering av svar &lt;/span&gt;&lt;br&gt;
&lt;form name="frmEnkat" method="POST" action="&lt;%=MM_editAction%&gt;"&gt;
&lt;table width="400" border="0" cellspacing="2" cellpadding="2"&gt;
&lt;tr&gt;
&lt;td width="257" colspan="2"&gt;Fr&aring;ga 1 ? &lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="top"&gt;
&lt;td colspan="2"&gt;&lt;table width="200"&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label&gt;
&lt;input type="radio" name="Manellerkvinna" value="Man"&gt;
Man&lt;/label&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label&gt;
&lt;input type="radio" name="Manellerkvinna" value="Kvinna"&gt;
Kvinna&lt;/label&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="middle" class="sep"&gt;
&lt;td height="2" colspan="2"&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="top"&gt;
&lt;td colspan="2"&gt;Fr&aring;ga 2?&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="top"&gt;
&lt;td colspan="2"&gt;&lt;input type="text" name="n" value="I år, tack!" onFocus="if(this.value=='I år, tack!')this.value='';"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="top"&gt;
&lt;td colspan="2" class="sep"&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="top"&gt;
&lt;td colspan="2"&gt;Fr&aring;ga 3? &lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="top"&gt;
&lt;td colspan="2"&gt;&lt;table width="200"&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label&gt;
&lt;input type="radio" name="hurbordu" value="I flerbostadshus"&gt;
I flerbostadshus&lt;/label&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label&gt;
&lt;input type="radio" name="hurbordu" value="Radhus/Villa/Stuga"&gt;
Radhus/Villa/Stuga&lt;/label&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="top"&gt;
&lt;td colspan="2" class="sep"&gt;&nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="top"&gt;
&lt;td colspan="2"&gt;Fr&aring;ga 4? &lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="top"&gt;
&lt;td colspan="2"&gt;&lt;table width="238"&gt;
&lt;tr&gt;
&lt;td width="204"&gt;&lt;label&gt;
&lt;input type="checkbox" name="q4" value="16"&gt;
Åker allmänna färdmedel&lt;/label&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label&gt;
&lt;input type="checkbox" name="q4" value="8"&gt;
Åker bil&lt;/label&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label&gt;
&lt;input type="checkbox" name="q4" value="4"&gt;
Cyklar&lt;/label&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label&gt;
&lt;input type="checkbox" name="q4" value="2"&gt;
Går&lt;/label&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;&lt;label&gt;
&lt;input type="checkbox" name="q4" value="1"&gt;
Annat&lt;/label&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;&lt;/form&gt; and so on........
</font id=code></pre id=code>

And how do i concenate two fields or more from checkboxes in a form and insert the value to the db?

Reply to this topic