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>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/enkat.asp" -->
<%
' *** 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 & "?" & Server.HTMLEncode(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") = "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 <> "" 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
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Tyck till - Registrering</title>
<link href="include/include.css" rel="stylesheet" type="text/css">
</head>
<body>
<span class="verdanastor">Tyck till - Registrering av svar </span><br>
<form name="frmEnkat" method="POST" action="<%=MM_editAction%>">
<table width="400" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="257" colspan="2">Fråga 1 ? </td>
</tr>
<tr valign="top">
<td colspan="2"><table width="200">
<tr>
<td><label>
<input type="radio" name="Manellerkvinna" value="Man">
Man</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="Manellerkvinna" value="Kvinna">
Kvinna</label></td>
</tr>
</table></td>
</tr>
<tr valign="middle" class="sep">
<td height="2" colspan="2"> </td>
</tr>
<tr valign="top">
<td colspan="2">Fråga 2?</td>
</tr>
<tr valign="top">
<td colspan="2"><input type="text" name="n" value="I år, tack!" onFocus="if(this.value=='I år, tack!')this.value='';">
</td>
</tr>
<tr valign="top">
<td colspan="2" class="sep"> </td>
</tr>
<tr valign="top">
<td colspan="2">Fråga 3? </td>
</tr>
<tr valign="top">
<td colspan="2"><table width="200">
<tr>
<td><label>
<input type="radio" name="hurbordu" value="I flerbostadshus">
I flerbostadshus</label></td>
</tr>
<tr>
<td><label>
<input type="radio" name="hurbordu" value="Radhus/Villa/Stuga">
Radhus/Villa/Stuga</label></td>
</tr>
</table></td>
</tr>
<tr valign="top">
<td colspan="2" class="sep"> </td>
</tr>
<tr valign="top">
<td colspan="2">Fråga 4? </td>
</tr>
<tr valign="top">
<td colspan="2"><table width="238">
<tr>
<td width="204"><label>
<input type="checkbox" name="q4" value="16">
Åker allmänna färdmedel</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="q4" value="8">
Åker bil</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="q4" value="4">
Cyklar</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="q4" value="2">
Går</label></td>
</tr>
<tr>
<td><label>
<input type="checkbox" name="q4" value="1">
Annat</label></td>
</tr>
</table></form> 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?