Search File to see if appointment already exists for 30 min intervals

Reply

Join Date: May 2004
Posts: 1,478
Reputation: mikeandike22 is an unknown quantity at this point 
Solved Threads: 18
mikeandike22's Avatar
mikeandike22 mikeandike22 is offline Offline
Nearly a Posting Virtuoso

Search File to see if appointment already exists for 30 min intervals

 
0
  #1
Mar 14th, 2008
Ok So right now I am using a script called MicroCalendar to setup a client calendar where A client can add an appointment to it but I need to put something into place that makes sure that they cannot overlap appointments..right Now im just saving appointments to txt files with the date of the appointment on them..here is my current code, i have not tried to check the half hour interval yet..

  1. <?php
  2. $myFile = "appointment $_POST[day]-$_POST[month]-$_POST[year].txt";
  3. $fh = fopen($myFile, 'w');
  4. fclose($fh);
  5. $fh1 = fopen($myfile, 'a');
  6. if($_POST[ok])
  7. {
  8. $stringData = "$_POST[name], scheduled an appointment at $_POST[hour]:$_POST[minute] on $_POST[day]-$_POST[month]-$_POST[year]";
  9. $handle = @fopen($file, 'r');
  10. $contents = @fread($handle, filesize($file));
  11. $strPos = strpos( $stringdata , $contents);
  12. if ($strPos!== false)
  13. {
  14. fwrite($fh, $stringData);
  15. fclose($fh);
  16. echo "<br>$_POST[name], scheduled an appointment at $_POST[hour]:$_POST[minute] on $_POST[day]-$_POST[month]-$_POST[year]";
  17. }
  18. ?>
My Daniweb Blog: This,That, and Everything Else (Blog contest winner)

GetFirefox!
GetOpera!






Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 224
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Search File to see if appointment already exists for 30 min intervals

 
0
  #2
Mar 14th, 2008
If it's on the web and you're already using PHP you might want to look into using a MySQL database instead of a flatfile, they are much easier to work with.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 1,478
Reputation: mikeandike22 is an unknown quantity at this point 
Solved Threads: 18
mikeandike22's Avatar
mikeandike22 mikeandike22 is offline Offline
Nearly a Posting Virtuoso

Re: Search File to see if appointment already exists for 30 min intervals

 
0
  #3
Mar 16th, 2008
Ok I wrote it like this for the code using sql..im not so great with PHP so maybe you could lend me a hand on getting this fixed..at the moment it doesnt do anything.
  1. <?php
  2. $host="localhost"; // Host name
  3.  
  4. $username="root"; // Mysql username
  5.  
  6. $password="original"; // Mysql password
  7.  
  8. $db_name="cutting_edge"; // Database name
  9.  
  10. $tbl_name="appointment"; // Table name
  11.  
  12. // Connect to server and select databse.
  13.  
  14. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  15.  
  16. mysql_select_db("$db_name")or die("cannot select DB");
  17.  
  18.  
  19.  
  20. if($_POST[ok])
  21.  
  22. {
  23.  
  24. $date = "$_POST[day]-$_POST[month]-$_POST[year]";
  25. $name = $_POST['name'];
  26. $time = "$_POST[hour]:$_POST[minute]";
  27. $time1 = "$_POST[hour]:00";
  28. $time2 = "$_POST[hour]:30";
  29.  
  30. // To protect MySQL injection (more detail about MySQL injection)
  31.  
  32. $date = stripslashes($date);
  33.  
  34. $name = stripslashes($name);
  35.  
  36. $date = mysql_real_escape_string($date);
  37.  
  38. $name = mysql_real_escape_string($name);
  39. $time = stripslashes($time);
  40.  
  41. $time = mysql_real_escape_string($time);
  42.  
  43.  
  44.  
  45. $sql="SELECT * FROM $tbl_name WHERE date='$date' and time='$time1'";
  46. $result=mysql_query($sql);
  47. if( $result == 0 ){
  48.  
  49. $sql="SELECT * FROM $tbl_name WHERE date='$date' and time='$time2'";
  50. $result=mysql_query($sql);
  51. if($result == 0){
  52. $sql ="INSERT INTO appointment VALUES( '$date', '$time', '$name' )";
  53. mysql_query($sql);
  54. }
  55.  
  56. }
  57.  
  58. }
  59.  
  60. ?>
My Daniweb Blog: This,That, and Everything Else (Blog contest winner)

GetFirefox!
GetOpera!






Reply With Quote Quick reply to this message  
Join Date: May 2004
Posts: 1,478
Reputation: mikeandike22 is an unknown quantity at this point 
Solved Threads: 18
mikeandike22's Avatar
mikeandike22 mikeandike22 is offline Offline
Nearly a Posting Virtuoso

Re: Search File to see if appointment already exists for 30 min intervals

 
0
  #4
Mar 16th, 2008
Ok So I got it to Insert the data in the table but im havin a problem I want to check if the user entered something other than 00 or 30 for their appointment time but right now It isnt working it just gets to the if statement which evaluates as true for everything I enter
  1. <?php
  2. $host="localhost"; // Host name
  3.  
  4. $username="root"; // Mysql username
  5.  
  6. $password="original"; // Mysql password
  7.  
  8. $db_name="cutting_edge"; // Database name
  9.  
  10. $tbl_name="appoint"; // Table name
  11.  
  12. // Connect to server and select databse.
  13.  
  14. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  15.  
  16. mysql_select_db("$db_name")or die("cannot select DB");
  17.  
  18.  
  19.  
  20. if($_POST[ok])
  21.  
  22. {
  23.  
  24. $date = "$_POST[month]-$_POST[day]-$_POST[year]";
  25. $name = $_POST['name'];
  26. $time = "$_POST[hour]:$_POST[minute]";
  27. $min = $_POST['minute'];
  28.  
  29. if(($min != '00') || ($min != '30')){
  30. echo "Appointments are every 30 minutes please re-choose your time to accommodate this schedule";
  31. echo $min;
  32. }
  33. else{
  34. // To protect MySQL injection (more detail about MySQL injection)
  35.  
  36. $date = stripslashes($date);
  37.  
  38. $name = stripslashes($name);
  39.  
  40. $date = mysql_real_escape_string($date);
  41.  
  42. $name = mysql_real_escape_string($name);
  43. $time = stripslashes($time);
  44.  
  45. $time = mysql_real_escape_string($time);
  46.  
  47.  
  48.  
  49. $sql="SELECT * FROM $tbl_name WHERE date='$date' and time='$time'";
  50. $result=mysql_query($sql);
  51.  
  52. $count=mysql_num_rows($result);
  53.  
  54. if( $count == 0){
  55.  
  56. $sql ="INSERT INTO appoint VALUES( '$date', '$time', '$name' )";
  57. mysql_query($sql);
  58.  
  59. echo "$name, Scheduled an appointment for $time on $date";
  60. }
  61. else{
  62. echo "An Appointment Is already Scheduled for this time ";
  63. echo $time;
  64. }
  65. }
  66. }
  67. ?>
My Daniweb Blog: This,That, and Everything Else (Blog contest winner)

GetFirefox!
GetOpera!






Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC