Need some help with a php appointment script..

So ive written a script that takes information from a form and enters it into a mysql database. It works great. Information stores the way I want and everything is dandy, however I need to add one thing to this script and I’m not really sure how.

Before this script im going to show you below enters this information into the database i want the script to query the database, and in my ‘dropdate’ field and ‘pickupdate’ field, as “i seperated the 2 dates, dropoff date, and pickup date” I want the query to ask the database how many different rows there are presently dated between the dropdate and pickup date the user has entered in the form because i need to make sure the maximum capacity wont be overbooked, so if a maximum of 30 dogs can be booked in this hotel i need the database to make sure the number of rows it brings back between the dates the user entered dont exceed 29 and if they do i want the information to still be entered i just want the script to then echo a message saying that there is currently not enough room for the dog and someone will contact them shortly.

So how would I go about making that work with this script ive pasted below. Thank you so much in advance for all help.


<?php // contact to database $connect = mysql_connect("localhost", "boulder7_admin", "someone552083") or die ("Error , check your server connection."); mysql_select_db("boulder7_testdb"); //Get data in local variable $v_firstname=$_POST['firstname']; $v_lastname=$_POST['lastname']; $v_address=$_POST['address']; $v_city=$_POST['city']; $v_state=$_POST['state']; $v_zip=$_POST['zip']; $v_homephone=$_POST['homephone']; $v_cellphone=$_POST['cellphone']; $v_email=$_POST['email']; $v_dogname=$_POST['dogname']; $v_male=$_POST['male']; $v_female=$_POST['female']; $v_dogbreed=$_POST['dogbreed']; $v_dropdate=$_POST['dropdate']; $v_pickupdate=$_POST['pickupdate']; $v_ppl_aggr_yes=$_POST['ppl_aggr_yes']; $v_ppl_aggr_no=$_POST['ppl_aggr_no']; $v_dog_aggr_yes=$_POST['dog_aggr_yes']; $v_dog_aggr_no=$_POST['dog_aggr_no']; $v_food_aggr_yes=$_POST['food_aggr_yes']; $v_food_aggr_no=$_POST['food_aggr_no']; $v_dog_fixed_yes=$_POST['dog_fixed_yes']; $v_dog_fixed_no=$_POST['dog_fixed_no']; $v_instructions=$_POST['instructions']; // check for null values if ($v_firstname=="" or $v_lastname=="") echo "All fields must be entered, hit back button and re-enter information"; else{ $query="insert into contact(firstname,lastname,address,city,state,zip,homephone,cellphone,email,dogname,male,female,dogbreed,dropdate,pickupdate,ppl_aggr_yes,ppl_aggr_no,dog_aggr_yes,dog_aggr_no,food_aggr_yes,food_aggr_no,dog_fixed_yes,dog_fixed_no,instructions) values('$v_firstname','$v_lastname','$v_address','$v_city','$v_state','$v_zip','$v_homephone','$v_cellphone','$v_email','$v_dogname','$v_male','$v_female','$v_dogbreed','$v_dropdate','$v_pickupdate','$v_ppl_aggr_yes','$v_ppl_aggr_no','$v_dog_aggr_yes','$v_dog_aggr_no','$v_food_aggr_yes','$v_food_aggr_no','$v_dog_fixed_yes','$v_dog_fixed_no','$v_instructions')"; mysql_query($query) or die(mysql_error()); echo "Your appointment has been booked, Please confirm the booking by paying your $30 deposit by clicking here>>"; } ?>

Before you process the posting of the booking, you would query the dates.
Then, check the count($rows). So a query would be based on the calendar dates you inputed.

So, your would have to do a query something like this: (Only a guess as we do not know all your code.)

Let’s say $date1 (starting date) $date2 (Ending date)

$query=“SELECT * from contract where (dropdate =>$date1) and (dropdate<=$date2)”;
Execute the query…

That would grab all contracts within those dates. To check them, use count function. count($rows)

Not sure if that is what you were wanting, but, hope it helps…

Sponsor our Newsletter | Privacy Policy | Terms of Service