Forum Moderators: open

Message Too Old, No Replies

how to check date availability

         

weathercam

8:59 am on Nov 20, 2008 (gmt 0)

10+ Year Member



Have a photographer client whose main line of work is Weddings - currently on his site via simple one line form submission, user selects month & day then hits submit, user then sees if he is avaiable on that date.

I don't have access to his current server, to see how it's done, but this is the source code form submission. So I presume it's interogating a simple falt text file?

and Booking Form</font></strong></p>
<p style="margin-top: 0;"><font color="#FFFFFF" size="2" face="Arial, Helvetica, sans-serif">Enter
the date of your wedding below then click Submit to check our availability and
complete the Booking Form.</font></p>
<form action="availabilitycheck.asp" method="post" name="form1">
<p> <font color="#FFFFFF">
<select name="day">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
<option>11</option>
<option>12</option>
<option>13</option>
<option>14</option>
<option>15</option>
<option>16</option>
<option>17</option>
<option>18</option>
<option>19</option>
<option>20</option>
<option>21</option>
<option>22</option>
<option>23</option>
<option>24</option>
<option>25</option>
<option>26</option>
<option>27</option>
<option>28</option>
<option>29</option>
<option>30</option>
<option>31</option>
</select>
<select name="month">
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<select name="year">
<option>2008</option>
<option>2009</option>
<option>2010</option>
<option>2011</option>
<option>2012</option>
</select>
</font></p>
<p> <font color="#FFFFFF">
<input type="submit" name="Submit" value="Submit">
</font></p>
</form>

Client has to update via FTP a text file or something on a frequent basis as and when he gets bookings - so what's the most simple method to do this? Should add here I'm not at all skilled in DB's !

Thanks in anticipation

ZydoSEO

3:26 am on Nov 21, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is cake with a DB. Text file processing leaves too much room for error IMO. I'm not sure which DB you might have access to, but in SQL Server you could do something like:

NOTE: The following assumes that you only allow one booking per date.

Create a table to hold the dates for which the photographer is already booked.

CREATE TABLE tBookings (
BookedDate DATETIME NOT NULL
)

BookedDate should be the unique, primary key for the tBooking table. This means only one row per date can be inserted in the table.

If the user picks December 22nd, 2008 on the form in an attempt to book the photographer on that date then upon submit your code could use one of two approaches:

Approach 1: (Least desireable IMO)

Run the following query:

SELECT * FROM tBooking WHERE BookedDate = '12/22/2008'

If it returns 0 rows then the date is available and you can then perform an INSERT INTO tBooking (BookedDate) VALUES ('12/22/2008') to add a row for that date. If the original query returns 1 row then the date was not available (there was already a row in the table for that date).

Approach 2 (Most desireable IMO):

Simply attempt to insert a row into tBooking using INSERT INTO tBooking (BookedDate) VALUES ('12/22/2008'). If the insert succeeded then the date was available (no row previously existed for that date so the insert succeeded). If the insert fails with a DUPLICATE KEY VIOLATION error then you know there was already a row in tBooking for that date (i.e. he was already booked - date is not available).

Hope this helps.
Z

weathercam

8:25 am on Nov 24, 2008 (gmt 0)

10+ Year Member



thanks for that, wee bit over my head, I should be getting FTP access to the current server so hopefully will have a better idea as to what's there (or even copy it) - and it is as you say only "one booking per date".