Greetings,
I'm pretty new at ASP/SQL so if this seems like a no brainer, please enlighten me.
I have a form that is being used to track volunteer activities for employees in my company. The form has multiple input fields with the same id in case the employee has volunteered for multiple organizations.
First of all what's the beset practice out there for handling this scenario?
Currently I'm running a FOR loop which is creating a new record for every organization the employee has entered. Should I be doing this? Or, should I just have the form create one record with comma delineated values?
Secondly, if the user doesn't fill out all the files available, the script will still run the insert statement using the blank fields so what I end up with are empty records. Is there a way I can check the fields before I sent them? Any help is much appreciated as I have no direction in which to run.
Here's the ASP code:
I'm pretty new at ASP/SQL so if this seems like a no brainer, please enlighten me.
I have a form that is being used to track volunteer activities for employees in my company. The form has multiple input fields with the same id in case the employee has volunteered for multiple organizations.
First of all what's the beset practice out there for handling this scenario?
Currently I'm running a FOR loop which is creating a new record for every organization the employee has entered. Should I be doing this? Or, should I just have the form create one record with comma delineated values?
Secondly, if the user doesn't fill out all the files available, the script will still run the insert statement using the blank fields so what I end up with are empty records. Is there a way I can check the fields before I sent them? Any help is much appreciated as I have no direction in which to run.
Here's the ASP code:
Code:
<%
dim txt
Dim tempv
tempR = Request.Form("frmVolOrg1")
tempv = Request.Form("frmVolName")
If tempv <> "" THEN
Dim con, sql_insert, data_source
data_source = "Driver={SQL Server};Server=SOMESERVER;Database=SOMEdb;Uid=someUSR;Pwd=somePWD"
For w = 1 TO Request.Form("frmVolOrg1").Count AND Request.Form("frmVolHours1").Count AND Request.Form("frmOrgContact1").Count AND Request.Form("frmOrgPhone1").Count
sql_insert = "insert into tbl_main (volName, volTitle, volDepartment, volPhone, volMonth, volYear, volOrg, volHours, volContact, volConPhone) values " & _
"('"&Request.Form("frmVolName") & "','" & _
Request.Form("frmVolTitle") & "','" & _
Request.Form("frmVolDept") & "','" & _
Request.Form("frmVolPhone") & "','" & _
Request.Form("frmVolMonth") & "','" & _
Request.Form("frmVolYear") & "','" & _
Request.Form("frmVolOrg1").Item(w) & "','" & _
Request.Form("frmVolHours1").Item(w) & "','" & _
Request.Form("frmOrgContact1").Item(w) & "','" & _
Request.Form("frmOrgPhone1").Item(w)&"')"
Set con = Server.CreateObject("ADODB.Connection")
con.Open data_source
con.Execute sql_insert
con.Close
Next
Response.Redirect("allResults.asp")
Set con = Nothing
End If
%>
Comment