Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

null dates inserted into db?? 1

Status
Not open for further replies.

snix1

Programmer
Dec 12, 2000
107
0
0
US
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=&quot;admin/Confirmation.asp&quot; method=&quot;post&quot;>
<tr>
<td class=&quot;font1&quot; align=&quot;right&quot;>Date:</td>
<td><select name=&quot;cal_month&quot;
size=&quot;1&quot;>
<option value=&quot;1&quot; <% if CurrentMonth = 1 then %>SELECTED <%end if %>>January
<option value=&quot;2&quot; <% if CurrentMonth = 2 then %>SELECTED <%end if %> >February
<option value=&quot;3&quot; <% if CurrentMonth = 3 then %>SELECTED <%end if %>>March

etc.


</select>

<select name=&quot;cal_day&quot;
size=&quot;1&quot;>
<option value=&quot;1&quot;>1
<option value=&quot;2&quot;>2
<option value=&quot;3&quot;>3
<option value=&quot;4&quot;>4
<option value=&quot;5&quot;>5
etc.

</select>


<select name=&quot;cal_year&quot;
size=&quot;1&quot;>
<option value=&quot;<%=CurrentYear%>&quot;><%=CurrentYear %>
<option value=&quot;<%=LastYear%>&quot;><%=LastYear%>
</select>
</td>

Confirmation:

'CHECK FOR REQUIRED FIELDS

strReferralDate = Trim(Request.Form(&quot;cal_month&quot;)) & &quot;/&quot; & Trim(Request.Form(&quot;cal_day&quot;)) & &quot;/&quot; & Trim(Request.Form(&quot;cal_year&quot;))

...

if(strReferralDate = &quot;&quot;) then
strErrorMessage = strErrorMessage & &quot;<li class=&quot;&quot;font1&quot;&quot;>Referral Date&quot;
end if

Action:

strReferralDate = Trim(Request.Form(&quot;hidReferralDate&quot;))


'GETS THE REFERRAL ID OF THE LAST REFERRAL ENTERED
strSQL = &quot;SELECT MAX(Referral_generic_ID) as maxReferralID FROM Referral_Generic &quot;

set rstMaxID = dbConnection.execute(strSQL)
intReferralID = rstMaxID(&quot;maxReferralID&quot;)
if (isNull(intReferralID) = true) then
intReferralID = 1
else
intReferralID = intReferralID + 1
end if
dtcreateDate = date()

strSQL = &quot;INSERT INTO myTable(Referral_Generic_ID, Referral_FirstName, Referral_LastName, Referral_Provider, Referral_Date,Referral_ReferredBy, Referral_Other_Service, createDateTime) &quot; &_
&quot;VALUES(&quot; & intReferralID & &quot;,'&quot; & strReferralFirstName & &quot;', '&quot; & strReferralLastName & &quot;', &quot; &_
&quot;'&quot; & strProviderName & &quot;','&quot; & strReferralDate & &quot;', '&quot; & strReferredBy & &quot;','&quot; & strOther & &quot;','&quot; & dtcreateDate & &quot;')&quot;



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.
 
Ok i think one of error might be here
Code:
strReferralDate = Trim(Request.Form(&quot;cal_month&quot;)) & &quot;/&quot; & Trim(Request.Form(&quot;cal_day&quot;)) & &quot;/&quot; & Trim(Request.Form(&quot;cal_year&quot;))

this actually get back a minimum strReferralDate like &quot;//&quot; if the other fields are empty so this is not a valid date when you get back in
...
strReferralDate = Trim(Request.Form(&quot;[red]hid[/red]ReferralDate&quot;))

or could be the fact that you dont use same name as html form input
error in red
i hope this will solve something ________
George, M
 
Thanks for your reply. The HTML form inputs are cal_month, cal_day, and cal_year. I don't quite understand your reply. The code explicitly checks that the user has entered a date. I format the date like 2/3/2002
 
You can't check your strReferralDate for a null value, you must check for it being &quot;//&quot;:

Code:
if(strReferralDate = &quot;//&quot;) then
   strErrorMessage = strErrorMessage & &quot;<li class=&quot;&quot;font1&quot;&quot;>Referral Date&quot;
end if
--James
 
im not sure if u just didn't include it in your code but in the part where u check for the required fields....u didn't put any value in your hidden field which i assume is the &quot;hidReferralDate&quot;

this code should be included...

if(strReferralDate = &quot;&quot;) then
strErrorMessage = strErrorMessage & &quot;<li class=&quot;&quot;font1&quot;&quot;>Referral Date&quot;
else
'this is the part where u give valu to ur hidden field
document.all.hidReferralDate.value = strReferralDate
end if

hope it helps!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top