Jump to content

Recommended Posts

My prof ask me to create a salon online booking system . My question is what is the code for preventing a double booking.. I have 1 table named tblappointment and inside that there is   time, date and specialist .. Now I want my system to still record the data if the customer input time and date are already exist as long as the specialist is different.. and it will alert or give error message if customer input for time, date and specialist are already exist..

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/314795-php-prevent-double-booking/
Share on other sites

If the slots that can be booked are all regular intervals, put a UNIQUE constraint on (specialist, time) so, say, "Anthony, 10:00" can be entered once only. However if "Anthony, 10:01" were also valid then it gets more complicated.

  • Thanks 1

This is my booking area 👇by the way this is not an assignment, it's for my  capstone project , a requirement for me to graduate

 

<?php 
include('connection.php');
session_start();
error_reporting(0);
include('connection.php');
if(isset($_POST['submit']))
  {

    $name=$_POST['name'];
    $email=$_POST['email'];
    $vaccinated=$_POST['vaccinated'];
    $vacid=$_POST['vacid'];
    $services=$_POST['services'];
     $specialist=$_POST['specialist'];
    $adate=$_POST['adate'];
    $atime=$_POST['atime'];
    $phone=$_POST['phone'];
    $userid=$_POST['userid'];
    $aptnumber = mt_rand(100000000, 999999999);
    
  
    $query=mysqli_query($con,"insert into tblappointment(Booking_Number,Name,Email,vaccinated_orNot,vax_id,PhoneNumber,Booking_Date,Booking_Time,Services,specialist,user_id) value('$aptnumber','$name','$email','$vaccinated','$vacid','$phone','$adate','$atime','$services','$specialist','$userid')");
    if ($query) {
$ret=mysqli_query($con,"select Booking_Number from tblappointment where Email='$email' and  PhoneNumber='$phone'");
$result=mysqli_fetch_array($ret);
$_SESSION['aptno']=$result['Booking_Number'];
 echo "<script>window.location.href='thankyou.php'</script>"; 
  }
  else
    {
      $msg="Something Went Wrong. Please try again";
    }

  
}

?>
<!DOCTYPE html>
<html lang="en">
  <head>
    <title>Vaniza's Wellness||Booking Area</title>
        
  </head>
  <body style="background-image: url('img/bg.jpg');">
  <?php include_once('header.php');?>
   

    <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>

    <script>
        $(document).ready(function(){
            $(window).on('scroll', function(){
                if ($(window).scrollTop()) {
                    $("header").addClass('bgc');
                }else{
                    $("header").removeClass('bgc');
                }
            });
        });
    </script>


<br>
<div>
    <section style="margin-left: auto;margin-right: auto;width: 50%;">
      <div class="container-fluid px-0" style="border:1px solid black;box-shadow: 5px 5px 5px gray;">
        
            <div class="text">
              <div class="overlay"></div>
              <div class="appointment-wrap">
                
                <h3 class="mb-2">BOOKING</h3>

                <form action="#" method="post" class="appointment-form">
                  <div class="row">
                    <div class="col-sm-12">
                      <div class="form-group">
                        <input type="text" class="form-control" id="name" placeholder="Name" name="name" required="true" style="">
                      </div>
                    </div>
                    <div class="col-sm-12">
                      <div class="form-group">
                        <input type="text" class="form-control" id="userid" placeholder="User ID" name="userid" required="true" style="">
                      </div>
                    </div>
                    <div class="col-sm-12">
                      <div class="form-group">
                        <input type="email" class="form-control" id="appointment_email" placeholder="Email" name="email" required="true">
                      </div>
                    </div>
                   
                    <div class="col-sm-12">
                      <div class="form-group">
                        <div class="select-wrap">
                          <div class="icon"><span class="ion-ios-arrow-down"></span></div>
                          <select name="services" id="services" required="true" class="form-control">
                            <option value="">Select Services</option>
                            <?php $query=mysqli_query($con,"select * from tblservices");
              while($row=mysqli_fetch_array($query))
              {
              ?>
                           <option value="<?php echo $row['ServiceName'];?>"><?php echo $row['ServiceName'];?></option>
                           <?php } ?> 
                          </select>
                        </div>
                      </div>
                    </div>
                      <div class="col-sm-12">
                    <div class="form-group">
                        <div class="select-wrap" style="">
                          <div class="icon"><span class="ion-ios-arrow-down"></span></div>
                          <select name="specialist" id="specialist" required="true" class="form-control">
                            <option value="">    Select Specialist</option>
                            <?php $query=mysqli_query($con,"select * from employees");
                            while($row=mysqli_fetch_array($query))
                          {  ?>
                            <option value="<?php echo $row['employee_id'];?>"><?php echo $row['employee_name'];?></option>
                               <?php } ?> 

                        </select>
                        </div>
                      </div>
                    </div>

                   
                        
                    <div class="col-sm-12">
                      <div class="form-group">
                        <input type="text" class="form-control appointment_date" placeholder="Date" name="adate" id='adate' required="true">
                      </div>    
                    </div>
                    <div class="col-sm-12">
                      <div class="form-group">
                        <input type="text" class="form-control appointment_time" placeholder="Time" name="atime" id='atime' required="true">
                      </div>
                    </div>
                    <div class="col-sm-12">
                      <div class="form-group">
                        <input type="text" class="form-control" id="phone" name="phone" placeholder="Phone" required="true" maxlength="10" pattern="[0-9]+">
                      </div>
                    </div>
                    <div style="display: flex;">
                      
                     <div style="width: 50%;border: 0px;">

                                        
                                            <select name="vaccinated" class="form-control" id="vaccinated" required>
                                                <option value selected >Vaccinated or Not</option>
                                                <option value="vaccinated">Vaccinated</option>
                                                <option value="not">Not</option>
                                                
                                            </select>
                                          
                              </div>
                        
                               <div style="width: 50%;">
                                            
                                            <input name="vacid" type="text" id="vacid" class="form-control" required placeholder="Vaccination Id/Control NUmber">
                                </div>
                  </div>

                  <div class="form-group" style="margin-right: auto;margin-left: auto;margin-bottom: 10px;">
                    <input type="submit" name="submit" value="Make an Appointment" class="btn btn-primary">
                  </div>
                </form>
              </div>
            
          <div class="one-third">
            <div class="img" style="background-image: url(images/bg-1.jpg);"></div>
          </div>
        </div>
      </div>

      </div>

    </section>

    </div>
    <br>


    
  

 

    
  </body>
</html>

Screenshot_2022-05-16-02-50-13-31.jpg

To me, that table looks more like a spreadsheet than a relational DB table, containing customer data as well as appointment data. I do not see any indication of the duration of the appointment nor a time until so how do you know when it is due to end?

If you don't know that you cannot check for overlapping appointments.

1 hour ago, Barand said:

Do you have regular bookable timeslots?

Some weird programming stuff going on in there too.

You add a new appointment then immediately query the table looking for the booking number of the email and phone number just added. Why? If the customer has been before you would probably get the booking number of their earliest appointment and not the latest. Secondly, you have just generated the booking number using mt_rand() so you already know what it is! Why not use an auto_incrementing booking number and then just call last_insert_id() to get the value?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.