943,769 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 1364
  • PHP RSS
Mar 14th, 2008
0

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

Expand Post »
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..

PHP Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 33
Solved Threads: 19
Nearly a Posting Virtuoso
mikeandike22 is offline Offline
1,496 posts
since May 2004
Mar 14th, 2008
0

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

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.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005
Mar 16th, 2008
0

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

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.
PHP Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 33
Solved Threads: 19
Nearly a Posting Virtuoso
mikeandike22 is offline Offline
1,496 posts
since May 2004
Mar 16th, 2008
0

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

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
PHP Syntax (Toggle Plain Text)
  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. ?>
Reputation Points: 33
Solved Threads: 19
Nearly a Posting Virtuoso
mikeandike22 is offline Offline
1,496 posts
since May 2004

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: turn this array into a form
Next Thread in PHP Forum Timeline: Time in php?





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC