473,387 Members | 1,504 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

ASP code that will limit how many people can sign up for a particular appointment

4
I am creating a dreamweaver asp form that will be published on our website. My intent is for students to look at a list of dates and times and sign up for one of them. Once a student has signed up for a date, that date will no longer appear on the form. THe data will dump into access. So far I have a form that Allows a person to sign up for a particular date, but I do not know how to make that date read the database and realize it is taken and no display it or atleast not allow someone else to sign up on the same date. I am very new at asp. So far I have done okay, but now I am lost. Thank you for any help!

Michelle
Apr 12 '10 #1
7 2522
jhardman
3,406 Expert 2GB
first off, in your db set the date column to be unique (in other words, the db will not allow two entries with identical values in that field). It is easy then to catch an error and display "This date has been taken by someone else".

second, it might be easier to keep a list of open dates, and when one is selected, remove that date from the list. Otherwise, I would say you have to loop through the appointments already set in order at the same time you are looping through the dates you are displaying, and only display the dates that don't match. Does this make sense? Do you need help with the coding? If so let me know which method you want to use.

Jared
Apr 16 '10 #2
mkelly
4
@jhardman
Jared, I think that your first option sounds the easiest. I have selected the unique option in my Database and now it will not let you select a date that has already been taken. The problem is that if you do select a date it gives you an error that wouldn't make sense to the user. Can you help me with the ASP coding so that it will display "That date has been taken by someone else". Thank you so much for you help.
Michelle
Apr 28 '10 #3
jhardman
3,406 Expert 2GB
@mkelly
first you need to let the script engine know that you are prepared to handle errors (this needs to be above the line that generates the error):
Expand|Select|Wrap|Line Numbers
  1. on error resume next
then you need to detect whether an error occurred (this needs to be after the line that will cause the error):
Expand|Select|Wrap|Line Numbers
  1. if err.number <> 0 then
this will of course just detect ANY error, so might not be the best choice, but you could probably figure out what error number a duplicate appointment would make, right? just response.write the err.number. Anyway, the last thing you need to do is handle the error (this goes immediately after the if line above):
Expand|Select|Wrap|Line Numbers
  1.    response.write "This appointment date has already been chosen"
  2.    error.clear 'resets the error object so you can use it again
  3. end if
Let me know if this helps.

Jared
Apr 28 '10 #4
mkelly
4
@jhardman
Jared, thank you so much for you help. This was a quick fix to my problem. I would love to see the coding for looping through dates and only seeing the dates that don't match. This seems well out of my knowledge base. If you have time, I would appreciate seeing this code so that I can possibly use it for future projects. Again, thank you so much!!
Michelle
Apr 30 '10 #5
jhardman
3,406 Expert 2GB
OK, here is a simple code that uses nested loops to check the values of dates against each other. I simplified the code as much as possible, but it can be easily adjusted to check values in a db. Hope this helps.
Expand|Select|Wrap|Line Numbers
  1. <%
  2. dim x, dateArray, i, apptDate
  3. i = 0
  4. dateArray = split("5/6/2010 11:00:00 AM,5/6/2010 2:00:00 PM,5/6/2010 5:00:00 PM",",")
  5. for x = 0 to 23
  6.    apptDate = dateadd("h", x, "5/6/2010 8:00:00 AM")
  7.  
  8.    do while cdate(dateArray(i)) < apptDate
  9.       i = i + 1
  10.       if i > ubound(dateArray) then 
  11.          i = ubound(dateArray)
  12.          exit do
  13.       end if
  14.    loop
  15.  
  16.    if apptDate = cdate(dateArray(i)) then
  17.       response.write "Appointment taken<br>" & vbNewLine
  18.    else
  19.       response.write apptDate & "<br>" & vbNewLine
  20.    end if
  21.  
  22. next
  23. %>
May 6 '10 #6
mkelly
4
Jared, I have entered this code in just as it is in my form, but keep getting a cdate error. As I said in my first post. I have just started designed asp forms in the last month or so and have no knowledge or training. I am attaching my code to see if that will help. I can not thank you enough for your help.
Expand|Select|Wrap|Line Numbers
  1. </head>
  2. <!--#include virtual="includes/protect.asp"-->
  3. <!--#include file="../connections/dbcon.asp"-->
  4. <%
  5.   'this code block puts the data into the DB if the Submit button was clicked and the form validated.
  6.   Submitted = False ' we'll use this below to determine if we display the form, or a message to the user.
  7.   if request.form("Submit") <> "" then  'If the form was submitted, add the registration, otherwise all this code is skipped.
  8.      set rsRegistration = server.CreateObject("ADODB.Recordset") 'create the recordset to add a record
  9.      rsRegistration.activeconnection = con 'set up the connection, defined in dbcon.asp included above.
  10.      rsRegistration.cursorlocation = 3  'always use these settings
  11.      rsRegistration.cursortype = 3
  12.      rsRegistration.locktype = 3  'only needed if DB is to be updated, otherwise skip it
  13.      rsRegistration.source = "SELECT Top 1 * FROM Appointments" 'the query will bring in one record as a 'template' for the add.
  14.      rsRegistration.open
  15.      'response.write("recordcount = " & rsRegistration.recordcount)
  16.      'if rsRegistration.recordcount > 0 then 'make sure we got at least one record.
  17.      if rsRegistration.recordcount > 0 then 'make sure we got at least one record.
  18.         rsRegistration.addnew 'add a new record
  19.         for each obj in rsRegistration.fields  'this loops through all the fields in the record.
  20.            if obj.name <> "ID" then  'since ID is autonumber, we can't assign a value to it.
  21.                dim x, dateArray, i, apptDate
  22. i = 0
  23. dateArray = split("5/6/2010 11:00:00 AM,5/6/2010 2:00:00 PM,5/6/2010 5:00:00 PM")
  24. for x = 0 to 23
  25.    apptDate = dateadd("h", x, "5/6/2010 8:00:00 AM")
  26.  
  27.    do while cdate(dateArray(i)) < apptDate
  28.       i = i + 1
  29.       if i > ubound(dateArray) then 
  30.          i = ubound(dateArray)
  31.          exit do
  32.       end if
  33.    loop
  34.  
  35.       response.write "<!-- x = " & x & vbNewLine
  36.       response.write "apptDate = " & apptDate & vbNewLine
  37.       response.write "i = " & i & vbNewLine
  38.       response.write "dateArray(i) = " & dateArray(i) & " -->" & vbNewLine
  39.  
  40.    if apptDate = cdate(dateArray(i)) then
  41.       response.write "Appointment taken<br>" & vbNewLine
  42.    else
  43.       response.write apptDate & "<br>" & vbNewLine
  44.    end if
  45.    next
  46.  
  47.                rsRegistration(obj.name) = request.form(obj.name) 'assign the value of the form field to the recordset field
  48.            end if
  49.  
  50.            Next
  51.         rsRegistration.update 'sends the new record to the DB.
  52.         Submitted = True
  53.         end if
  54.         rsRegistration.close  'close the connection to the data source - IMPORTANT to ALWAYS do this
  55.      set rsRegistration = nothing  'remove the recordset from teh server's memory, also very important.
  56.   end if
  57.  
  58. %>
  59.  
  60. <body>
  61. <% IF NOT Submitted Then 'display the form if not submited %>
  62. <div id="cform">
  63. <form name="Appointments" method="post" action="Appointments.asp">
  64. <fieldset>
  65.  
  66.     <legend>International Services Appointment</legend>
  67.  
  68.         <label for="UIN" class="required">UIN: <em>*</em></label>
  69.  
  70.       <span id="sprytextfield1">
  71.       <input type="text" name="UIN" id="UIN" />
  72.       <span class="textfieldRequiredMsg">UIN is required.</span><span class="textfieldInvalidFormatMsg">UIN is 9 numbers begining with 814</span></span><br />
  73.       <label for="FirstName" class="required">First Name: <em>*</em></label>
  74.       <span id="sprytextfield2">
  75.       <input type="text" name="FirstName" id="FirstName" />
  76.       <span class="textfieldRequiredMsg">First Name is required.</span></span><br />
  77.       <label for="LastName" class="required">Last Name: <em>*</em></label>
  78.       <span id="sprytextfield3">
  79.       <input type="text" name="LastName" id="LastName" />
  80.       <span class="textfieldRequiredMsg">Last Name is required.</span></span><br />
  81.       <label for="AppointmentType" class="required">What do you wish to discuss at your appointment? <em>*</em></label><br />
  82.     <span id="spryselect1">
  83.     <select name="AppointmentType" id="AppointmentType">
  84.       <option value="">please make a selection</option>
  85.         <option value="Study Abroad">Study Abroad</option>
  86.         <option value="OPT/CPT">OPT/CPT</option>
  87.         <option value="Change of status">Change of status</option>
  88.         <option value="Extension">Extension</option>
  89.         <option value="Other immigration issues">Other immigration issues</option>
  90.         <option value="Tax questions">Tax questions</option>
  91.         <option value="Social Security Card">Social Security Card</option>
  92.     </select>
  93.       <span class="selectRequiredMsg">Please select an item.</span></span><br />
  94.  
  95. <label for="Appointment" class="required">Appointment Time: <em>*</em></label>
  96.       <span id="spryselect2">      
  97.       <select name="Appointment" id="Appointment">
  98.         <option value="">Select an Appointment Time</option>
  99.         <option value="5/6/2010 11:00:00 AM">5/6/2010 11:00:00 AM</option>
  100.         <option value="5/6/2010 2:00:00 PM">5/6/2010 2:00:00 PM</option>
  101.         <option value="5/6/2010 5:00:00 PM">5/6/2010 5:00:00 PM</option>
  102.       </select>
  103.       <span class="selectRequiredMsg">Please select an appointment time.</span></span><br /><br />
  104.  
  105.  
  106.      <span class="style3 style1">*</span>
  107.      <span id="sprycheckbox1">
  108.         <input type="checkbox" name="InfoSession" value="Yes" > 
  109.         <span class="checkboxRequiredMsg">Please check box.</span></span>If you wish to schedule an appointment concerning Study Abroad, OPT, COT or tax issues, you must first attend an information session.  By checking here, you are stating that you have already attended an information session on one of the above issues and still have questions. <br /><br />
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117. </fieldset>   
  118. <div align="center"><input name="Submit" type="submit" value="Submit Registration" /></div>     
  119. </fieldset>       
  120. </form>
  121. </div>
  122. <script type="text/javascript">
  123. <!--
  124. var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1", "custom", {pattern:"814000000", hint:"814######", useCharacterMasking:true, validateOn:["blur"]});
  125. var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2", "none", {validateOn:["blur"]});
  126. var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "none", {validateOn:["blur"]});
  127. var spryselect1 = new Spry.Widget.ValidationSelect("spryselect1", {validateOn:["blur"]});
  128. var spryselect2 = new Spry.Widget.ValidationSelect("spryselect2",{validateOn:["blur"]});
  129. var sprycheckbox1 = new Spry.Widget.ValidationCheckbox("sprycheckbox1", {validateOn:["blur"]});
  130. //-->
  131. </script>
  132. <% else 'display a message, send an email or whatever else if the form was submitted%>
  133.  
  134.  
  135. <!--This is an HTML comment - They are visible to the end user, ASP comments are not.
  136.     This is where I would send an email if you were going to do that-->
  137. <% end if 'end of the if Not Submitted block %>
  138. </body>
  139. </html>
May 7 '10 #7
jhardman
3,406 Expert 2GB
hmm. I don't know why you are getting an error, mine worked just fine. Here is my test page

By the way, please use the code formatting button (#) when you post code, it makes it much easier to read.

Jared
May 8 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: Wilk Teverbaugh | last post by:
I'm using get rows to build a table for a calendar. The specific view for this calendar is for an entire month. Each appointment slot is one half hour long. If I were to generate a page for the...
242
by: James Cameron | last post by:
Hi I'm developing a program and the client is worried about future reuse of the code. Say 5, 10, 15 years down the road. This will be a major factor in selecting the development language. Any...
26
by: Simon | last post by:
I'm doing a survey. When do you think GNU/Linux will be ready for the average Joe? What obstacles must it overcome first?
109
by: Andrew Thompson | last post by:
It seems most people get there JS off web sites, which is entirely logical. But it is also a great pity since most of that code is of such poor quality. I was looking through the JS FAQ for any...
2
by: greatbooksclassics | last post by:
Open Source DRM? What does everyone think about it? Will Open Source DRM ever catch up to MS DRM? Will DRM ever be integrated into common LAMP applications?...
143
by: suri | last post by:
Hello I downloaded glibc and tried looking for the code that implements the sine function i couldnt find the file. i went to the math directory and found math.h.. i guess that needs to be...
28
by: Noone Here | last post by:
AIUI, it was not all that long ago when the threat to personal users, was attachments that when executed compromised machines with keyloggers, trojans, etc. Now it seems that the big problem is...
29
by: Gernot Frisch | last post by:
Hi, I have no clue. - I want to align the red, green, blue boxes in one line - red,green,blue must be 45px high - red (center) must be as wide as possible - yellow must start exactly below...
0
by: palomine1234 | last post by:
PAYPAL MAGIC!!! TURN $5 INTO $15,000 IN ONLY 30 DAYS...HERES HOW! This is a Money Scheme and Not, I repeat... This is Not a Scam!!!
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.