All this would work if my database was updated by separate statments which update each form separately. However, there is ONLY for universal code that updates every page on the database depending on its name which has to match the name on the form, and depending on its datatype...
Since you really understand what's going on I will include this code for you, maybe you can help... i know that changing the name for each checkbox to the same name would make my life a million times easier, but then the database will not know what's going on because each one of these separate names stands for a separate question, and this universal update will update ONLY one name if I remove the other 5 there's really 6 checkboxes, but I only put 2 to make things easier...
In order to do this, they had to have name of the form the same as the name of the database table. The name of the form elements is also the name of the database columns. Also there's 13 different pages, not 3, but again, I wanted to cut down on the code...
Here's the code... Any ideas how to deal with something like this, probably your stored procedure or trigger ideas, only I've never programmed one of these before...
The code is this page (save.asp) is quite brilliant only it throws conventional programming right out of the wnidow...
dim iUserID, iApplicationID, iFormPart, sTable, sUpdate, bError
iUserID = Session("UserID")
iApplicationID = Session("ApplicationID")
iFormPart = Request.Form("_formpart")
response.write(iFormPart)
if iFormPart <> 0 and iFormPart <> 13 then
sTable = "form25part" & iFormPart
' Get the table properties
dim rsTable
set rsTable = Server.CreateObject("ADODB
with objCommand
.CommandText = "TableProperties"
.Parameters.Append .CreateParameter("@TableNa
set rsTable = .Execute
end with
dim item, sqlUpdate, sValue, DataType
for each item in Request.Form
if left(item,1) <> "_" then
sValue = Request.Form(item)
if sValue = "" then
sValue="NULL"
else
' Get the datatype
with rsTable
.Find "column_name='" & item & "'", 0, adSearchForward, adBookmarkFirst
if .BOF or .EOF then
Response.Write("ERROR: Could not find datatype for column " & item & "<BR>")
DataType = ""
else
DataType = .Fields("datatype")
end if
end with
' Format the variable based on the datatype
if sValue = "" then
sValue = "NULL"
else
select case DataType
case "bit"
if sValue="on" then
sValue = 1
elseif not IsNumeric(sValue) then
sValue = "NULL"
end if
case "char", "varchar", "text"
if trim(sValue) <> "" then
sValue = "'" & SQLFriendly(sValue) & "'"
else
sValue = "NULL"
end if
case "datetime"
if IsDate(sValue) then
sValue = "'" & cDate(sValue) & "'"
else
sValue = "NULL"
end if
case "int"
if not isNumeric(sValue) then
sValue = "NULL"
end if
case "money"
Response.Write(item & " - " & sValue & "<BR>")
sValue = FormatCurrency(sValue,2,0,
case else
Response.Write("ERROR: Unknown Datatype '" & DataType & "' for column '" & item & "'")
bError = true
end select
end if
'if not isNumeric(sValue) then
' sValue = "'" & SQLFriendly(sValue) & "'"
'end if
end if
if DataType<>"" then
sUpdate = sUpdate & " [" & item & "]=" & sValue & ","
end if
end if
next
if sUpdate<> "" then
sUpdate = "UPDATE " & sTable & " SET " & sUpdate & " [Part" & iFormPart & "Complete]=" & Request.Form("_complete") & ", [Part" & iFormPart & "Updated_ts]='" & now() & "'" &_
" WHERE FK_ApplicationID=" & iApplicationID
else
sUpdate = "UPDATE " & sTable & " SET [Part" & iFormPart & "Complete]=" & Request.Form("_complete") & ", [Part" & iFormPart & "Updated_ts]='" & now() & "'" &_
" WHERE FK_ApplicationID=" & iApplicationID
end if
response.Write(sUpdate)
objConn.execute(sUpdate)
end if
if not bError then
dim s_target
s_target = Request.Form("_target")
select case s_target
case "Next": iFormPart = right("0" & cint(iFormPart)+1,2)
case "Previous": iFormPart = right("0" & cstr(cint(iFormPart)-1),2)
case else: iFormPart = s_target
end select
Response.Redirect("25-" & iFormPart & ".asp")
end if
Main Topics
Browse All Topics





by: nschaferPosted on 2007-05-17 at 08:49:37ID: 19109169
To start with, lets do a basic introduction into how check boxes work.
nce") = 0
nce") = "1" then
Lets say I have a form with the following checkboxes:
<input type="checkbox" name="check1" value="1" />
<input type="checkbox" name="check1" value="2" />
<input type="checkbox" name="check1" value="3" />
<input type="checkbox" name="check2" value="1" />
<input type="checkbox" name="check2" value="2" />
<input type="checkbox" name="check2" value="3" />
So I have a total of 6 check boxes on the page, but notice only two different names. This is common when the form is being generated by a database driven page.
If I check the 1st and 3rd checkboxes of each group, then I send the following information to the action page of the form.
check1 = "1,3"
check2 = "1,3"
The values of the selected checkbox in a comma-delimited string are sent to the action page of the form. Unchecked boxes are not sent at all. So lets say I didn't check any of the boxes named check2 the info sent to the action page would be:
check1 = "1,3" Note check2 is not even included.
So looking at your code, it appears that you have only two checkboxes on the form and that they have different names. If one or both of the checkboxes is not checked then they will not send any value to the save page.
Looking at your save.asp, one problem I see is code like the following: Request.form("LearnConfere
This is simply invalid code. You cannot set the value of an element of the Request object. The request object is read only. I'm not sure what you are trying to accomplish with this in any case.
What you need to do to update your database in your save page is to program your sql statement such that it inserts a 0 if the form item is empty.
if request.form("LearnConfere
sql = sql & "LearnConference = 1,"
else
sql = sql & "LearnConference = 0,"
end if
Using code like that to create your sql staement will allow you to put 1 in if the box is checked, and a 0 if it is not checked. Depending on your database you could also write a trigger such that when a record is updated if the field value is null to set it to 0. Another option is to use a stored procedure to update the table, and in the stored procedure have the logic to check for null value and convert it to a 0.
So there are a few ways you can handle this, depending on your coding style and the database you are using. I know you didn't post all of your code, and I'm not asking you to, but based on what I can see here there are a couple of concepts that you need to grasp better to resolve your issue.
I hope this helps,
Neal.