Hi! I have an application that allows users to enter records in a database via a form. The form has a date field which is represented as a dropdown on Month, Day, and year. The user enters other data as well and then hits submit. They get a confirmation screen then they hit submit and the record is stored. However, sometimes a "blank" record is stored with the date as 1/1/1900 and all other fields blank. I don't know how this happens. The form checks for required values. I can't reproduce it. Here's some code fragments referencing the date:
<table>
<form action="admin/Confirmation.asp" method="post">
<tr>
<td class="font1" align="right">Date:</td>
<td><select name="cal_month"
size="1">
<option value="1" <% if CurrentMonth = 1 then %>SELECTED <%end if %>>January
<option value="2" <% if CurrentMonth = 2 then %>SELECTED <%end if %> >February
<option value="3" <% if CurrentMonth = 3 then %>SELECTED <%end if %>>March
etc.
</select>
<select name="cal_day"
size="1">
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
etc.
</select>
<select name="cal_year"
size="1">
<option value="<%=CurrentYear%>"><%=CurrentYear %>
<option value="<%=LastYear%>"><%=LastYear%>
</select>
</td>
Confirmation:
'CHECK FOR REQUIRED FIELDS
strReferralDate = Trim(Request.Form("cal_month"
) & "/" & Trim(Request.Form("cal_day"
) & "/" & Trim(Request.Form("cal_year"
)
...
if(strReferralDate = ""
then
strErrorMessage = strErrorMessage & "<li class=""font1"">Referral Date"
end if
Action:
strReferralDate = Trim(Request.Form("hidReferralDate"
)
'GETS THE REFERRAL ID OF THE LAST REFERRAL ENTERED
strSQL = "SELECT MAX(Referral_generic_ID) as maxReferralID FROM Referral_Generic "
set rstMaxID = dbConnection.execute(strSQL)
intReferralID = rstMaxID("maxReferralID"
if (isNull(intReferralID) = true) then
intReferralID = 1
else
intReferralID = intReferralID + 1
end if
dtcreateDate = date()
strSQL = "INSERT INTO myTable(Referral_Generic_ID, Referral_FirstName, Referral_LastName, Referral_Provider, Referral_Date,Referral_ReferredBy, Referral_Other_Service, createDateTime) " &_
"VALUES(" & intReferralID & ",'" & strReferralFirstName & "', '" & strReferralLastName & "', " &_
"'" & strProviderName & "','" & strReferralDate & "', '" & strReferredBy & "','" & strOther & "','" & dtcreateDate & "')"
dbConnection.execute(strSQL)
When I print out my dates along the way, they're o.k.
Does anyone see anything wrong with this code? I hope this makes sense. Somehow a null string is being inserted for date, I guess. Thanks much.
<table>
<form action="admin/Confirmation.asp" method="post">
<tr>
<td class="font1" align="right">Date:</td>
<td><select name="cal_month"
size="1">
<option value="1" <% if CurrentMonth = 1 then %>SELECTED <%end if %>>January
<option value="2" <% if CurrentMonth = 2 then %>SELECTED <%end if %> >February
<option value="3" <% if CurrentMonth = 3 then %>SELECTED <%end if %>>March
etc.
</select>
<select name="cal_day"
size="1">
<option value="1">1
<option value="2">2
<option value="3">3
<option value="4">4
<option value="5">5
etc.
</select>
<select name="cal_year"
size="1">
<option value="<%=CurrentYear%>"><%=CurrentYear %>
<option value="<%=LastYear%>"><%=LastYear%>
</select>
</td>
Confirmation:
'CHECK FOR REQUIRED FIELDS
strReferralDate = Trim(Request.Form("cal_month"
...
if(strReferralDate = ""
strErrorMessage = strErrorMessage & "<li class=""font1"">Referral Date"
end if
Action:
strReferralDate = Trim(Request.Form("hidReferralDate"
'GETS THE REFERRAL ID OF THE LAST REFERRAL ENTERED
strSQL = "SELECT MAX(Referral_generic_ID) as maxReferralID FROM Referral_Generic "
set rstMaxID = dbConnection.execute(strSQL)
intReferralID = rstMaxID("maxReferralID"
if (isNull(intReferralID) = true) then
intReferralID = 1
else
intReferralID = intReferralID + 1
end if
dtcreateDate = date()
strSQL = "INSERT INTO myTable(Referral_Generic_ID, Referral_FirstName, Referral_LastName, Referral_Provider, Referral_Date,Referral_ReferredBy, Referral_Other_Service, createDateTime) " &_
"VALUES(" & intReferralID & ",'" & strReferralFirstName & "', '" & strReferralLastName & "', " &_
"'" & strProviderName & "','" & strReferralDate & "', '" & strReferredBy & "','" & strOther & "','" & dtcreateDate & "')"
dbConnection.execute(strSQL)
When I print out my dates along the way, they're o.k.
Does anyone see anything wrong with this code? I hope this makes sense. Somehow a null string is being inserted for date, I guess. Thanks much.