AngelSelmo Posted May 15, 2022 Share Posted May 15, 2022 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.. Quote Link to comment https://forums.phpfreaks.com/topic/314795-php-prevent-double-booking/ Share on other sites More sharing options...
Barand Posted May 15, 2022 Share Posted May 15, 2022 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. 1 Quote Link to comment https://forums.phpfreaks.com/topic/314795-php-prevent-double-booking/#findComment-1596284 Share on other sites More sharing options...
AngelSelmo Posted May 15, 2022 Author Share Posted May 15, 2022 Can you help me solve my code problem?I have no idea how to do it, can you give me sample code🥺 Quote Link to comment https://forums.phpfreaks.com/topic/314795-php-prevent-double-booking/#findComment-1596286 Share on other sites More sharing options...
Barand Posted May 15, 2022 Share Posted May 15, 2022 I can try to help you to write the code (I'm not doing your assignment for you). Do you have regular bookable timeslots? What is the structure of "tblappointment"? (and other tables you are using?) 1 Quote Link to comment https://forums.phpfreaks.com/topic/314795-php-prevent-double-booking/#findComment-1596287 Share on other sites More sharing options...
AngelSelmo Posted May 15, 2022 Author Share Posted May 15, 2022 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> Quote Link to comment https://forums.phpfreaks.com/topic/314795-php-prevent-double-booking/#findComment-1596288 Share on other sites More sharing options...
benanamen Posted May 15, 2022 Share Posted May 15, 2022 (edited) Is this code representative of what you have been taught in school? If so, your teacher needs schooling. Edited May 15, 2022 by benanamen Quote Link to comment https://forums.phpfreaks.com/topic/314795-php-prevent-double-booking/#findComment-1596292 Share on other sites More sharing options...
Barand Posted May 15, 2022 Share Posted May 15, 2022 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? Quote Link to comment https://forums.phpfreaks.com/topic/314795-php-prevent-double-booking/#findComment-1596293 Share on other sites More sharing options...
Barand Posted May 15, 2022 Share Posted May 15, 2022 PS Don't post pictures when asked for code or data structures - there is no way I can recreate a similar table at my end from that. If you want help don't give us extra work to do. Quote Link to comment https://forums.phpfreaks.com/topic/314795-php-prevent-double-booking/#findComment-1596294 Share on other sites More sharing options...
Barand Posted May 15, 2022 Share Posted May 15, 2022 Your tblAppointment contains a column "vaccinated_or_not". Does that refer to the customer, the specialist, the user, or the admin (all are referenced)? Quote Link to comment https://forums.phpfreaks.com/topic/314795-php-prevent-double-booking/#findComment-1596299 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.