Jump to content

Sarahpengie

Members
  • Posts

    13
  • Joined

  • Last visited

Sarahpengie's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Hi, Sorry Christian. Thanks Paul, I replaced my code with your code however I'm still having the same problem. It is still ignoring the endtime and allowing me to book 12.00-13.00 when 11.30-12.30 is booked :/
  2. OK thanks Do you know how I can fix my code to prevent the double bookings from occurring? Thanks again.
  3. Hi, Thanks, I've cleaned it up in my actual code, but when I try to edit it or delete it on this and using ctrl + Q it appears I don't have permission to make changes.
  4. <?php include('../config.php'); $Name = ''; $LessonDate = ''; $StartTime = ''; $EndTime = ''; if (isset($_POST['submit'])) { if(isset($_POST['Name'])){ $Name = $_POST['Name']; } if(isset($_POST['LessonDate'])){ $LessonDate = $_POST['LessonDate']; } if(isset($_POST['StartTime'])){ $StartTime = $_POST['StartTime']; } if(isset($_POST['EndTime'])){ $EndTime = $_POST['EndTime']; } $result = mysql_query("SELECT * FROM booking WHERE LessonDate = '".mysql_real_escape_string($LessonDate)."' AND (StartTime >= '".mysql_real_escape_string($StartTime)."' AND StartTime <= '".mysql_real_escape_string($EndTime)."')"); if(!$result) { die(mysql_error()); } if(mysql_num_rows($result) > 0) { die('<p>This date and time have already been booked. <a href="booking1.php">Please try another time</a>.</p>'); } else { //insert new user data into Users table $sql = "INSERT INTO `booking` ( `Name`, `LessonDate` , `StartTime` , `EndTime` ) VALUES( '{$Name}', '{$LessonDate}' , '{$StartTime}' , '{$EndTime}') "; mysql_query($sql) or die(mysql_error()); echo "Booking Successful.<br />"; echo "<a href='text.php'> Send reminder text </a>"; } } ?>
  5. Hi, I am creating a website for a project where you are able to book driving lessons. I have created code which (sort of) prevents double booking, however, I have I'm having a problem. If there is a booking stored in the DB at 11.30-12.30, if i try to book a lesson from 11-12 it prevents me from doing so, however if I try book from 12-1, it allows me to go ahead with the booking. The code I am using is below, I believe it has something to do with the line of code I have made "bold". Does anyone know how to solve this error? Thanks! <?php include('../config.php'); $Name = ''; $LessonDate = ''; $StartTime = ''; $EndTime = ''; if (isset($_POST['submit'])) { if(isset($_POST['Name'])){ $Name = $_POST['Name']; } if(isset($_POST['LessonDate'])){ $LessonDate = $_POST['LessonDate']; } if(isset($_POST['StartTime'])){ $StartTime = $_POST['StartTime']; } if(isset($_POST['EndTime'])){ $EndTime = $_POST['EndTime']; } $result = mysql_query("SELECT * FROM booking WHERE LessonDate = '".mysql_real_escape_string($LessonDate)."' AND (StartTime >= '".mysql_real_escape_string($StartTime)."' AND StartTime <= '".mysql_real_escape_string($EndTime)."')"); if(!$result) { die(mysql_error()); } if(mysql_num_rows($result) > 0) { die('<p>This date and time have already been booked. <a href="booking1.php">Please try another time</a>.</p>'); } else { //insert new user data into Users table $sql = "INSERT INTO `booking` ( `Name`, `LessonDate` , `StartTime` , `EndTime` ) VALUES( '{$Name}', '{$LessonDate}' , '{$StartTime}' , '{$EndTime}') "; mysql_query($sql) or die(mysql_error()); echo "Booking Successful.<br />"; echo "<a href='text.php'> Send reminder text </a>"; } } ?>
  6. I got it working!! Thanks for your help :)
  7. Ok, I changed it from LessonDate and now am using BookingID instead. So this is the code now: <?php include('../../config.php'); $BookingID = (int) $_GET['BookingID']; mysql_query("DELETE FROM `student` WHERE `BookingID` = '$BookingID' ") ; echo (mysql_affected_rows()) ? "Row deleted.<br /> " : "Nothing deleted.<br /> "; ?> It says row deleted when I click delete, but still doesn't actually delete anything. Sorry if I'm confusing. I really appreciate your help thanks.
  8. If I took this line here from the original code : $userid = (int) $_GET['userid']; and replaced 'userid' with 'LessonDate' what would I put in the brackets instead of (int)?
  9. Hi Kevin, Thanks for your help. I had previously tried this way too, but it still doesn't delete it from the database table? Thanks, Sarah.
  10. Thanks for your help Christian. I still a bit confused as to how to go about this. So should I change my code to something like this: <form action="../process-booking.php" method='POST'> <p><b>Select a Date:</b><br /><input type="date" value="Now" name='LessonDate'/> <p><b>Select a Start Time:</b><br /><input type='time' value="Now" name='StartTime'/> <p><b>Select an End Time:</b><br /><input type='time' value="Now" name='EndTime'/> <p><input type='submit' value='Book Now' /><input type='hidden' value='1' name='submitted' /> </form> <br> And in the process-booking.php form have some code which will check if the dates are taken? Or how should I do it? Thanks again for your help!
  11. Hi, I create a webpage where the admin can delete members. I am using the same code to delete bookings, however it seems it is not reading the IF statement and keeps returning "Nothing deleted". This code I have used is as follows: <?php include('../../config.php'); $LessonDate = ""; if (isset ($_GET['LessonDate']) ) {$LessonDate = $_GET['LessonDate'];} mysql_query("DELETE FROM `booking` WHERE `LessonDate` = '$LessonDate' ") ; echo (mysql_affected_rows()) ? "Row deleted.<br /> " : "Nothing deleted.<br /> "; ?> I did have to make some changes from the code I used when deleting members so this may be a problem. The original code is as follows: <?php include('../../config.php'); $userid = (int) $_GET['userid']; mysql_query("DELETE FROM `student` WHERE `userid` = '$userid' ") ; echo (mysql_affected_rows()) ? "Row deleted.<br /> " : "Nothing deleted.<br /> "; ?> Does anyone know what the problem could be? Thanks!
  12. Thanks for all ye're help! Barand, where in my code would I insert your code? Sorry I'm a bit clueless! Thanks again!
  13. Hi I am creating a website where a user can book a driving lesson. I am using mySQL and PHP. I have coded a booking system where users can book a lesson for a desired date and time, however I can't seem to find code to prevent double bookings from occurring. The code I have used in my booking form is as follows: <?php include('../config.php'); echo "<table border=1 >"; echo "<tr>"; echo "<td><b>LessonDate</b></td>"; echo "<td><b>StartTime</b></td>"; echo "<td><b>EndTime</b></td>"; echo "</tr>"; $result = mysql_query("SELECT * FROM booking") or trigger_error(mysql_error()); while($row = mysql_fetch_array($result)){ foreach($row AS $key => $value) { $row[$key] = stripslashes($value); } echo "<tr>"; echo "<td valign='top'>" . nl2br( $row['LessonDate']) . "</td>"; echo "<td valign='top'>" . nl2br( $row['StartTime']) . "</td>"; echo "<td valign='top'>" . nl2br( $row['EndTime']) . "</td>"; echo "</tr>"; } echo "</table>"; ?> If anyone could help me to prevent double bookings occurring that would be great Thanks in advance for your help Sarah.
×
×
  • 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.