Forums
This topic is locked
problems checking for duplicate insert
Posted 08 Feb 2008 18:38:32
1
has voted
08 Feb 2008 18:38:32 Ann Thomas posted:
HiCan someone please advise me what's the matter with this code. It is an appointments diary and the appointments keep going through to table when they shouldn't be.
<%
if Request.form("Enter"="Enter Appt Room 1" then
varTime = Request.form("select3"
varDate = Request.form("dateTxt"
varClient = Request.form("clientApptTbx"
varPatient = Request.form("patientApptTbx"
varRoomNo = 1
set rs7=Server.CreateObject("ADODB.Recordset"
rs7.open "select * from appts where dateAppt =#" & varDate & "# and timeAppt =" & varTime & "",conn,3
if rs7.RecordCount>0 then
response.write "<font color = 'red'>"
response.write "Sorry, that appointment has already been taken"
response.write "</font>"
Else
Dim records
conn.Execute "INSERT INTO appts(timeAppt,dateAppt,clientIDAppt,patientIDAppt,roomNo) VALUES" & _
"('" & varTime & "','" & varDate & "','" & varClient & "','" & varPatient & "','" & varRoomNo & "')" , records
if records=1 then
response.write "<font color = 'blue'>"
response.write "The appointment has been made"
response.write "</font>"
End if
End if
rs7.close
set rs7 = nothing
End if
%>
varTime is a number from 1 to 12, but shows as a time when in the select box.
varDate is a short date
There doesn't seem to be any other errors except that the appointment keeps going through whether there is already one the same in the table or not.
Is it something to do with the fact that time is a number, and I am telling the server to find time as text (or something like that).
The code
response.write "Sorry, that appointment has already been taken"
isn't displaying at all because the data is getting through
Thanks