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	
		$myFile = "appointment $_POST[day]-$_POST[month]-$_POST[year].txt";
		$fh = fopen($myFile, 'w');
		fclose($fh);
		$fh1 = fopen($myfile, 'a');
		if($_POST[ok])
		{ 
		 $stringData = "$_POST[name], scheduled an appointment at $_POST[hour]:$_POST[minute] on $_POST[day]-$_POST[month]-$_POST[year]";
		 $handle = @fopen($file, 'r');
		 $contents = @fread($handle, filesize($file));
		 $strPos = strpos( $stringdata , $contents);
		 if ($strPos!== false)
		 {
			 fwrite($fh, $stringData);
			 fclose($fh);
			 echo "<br>$_POST[name], scheduled an appointment at $_POST[hour]:$_POST[minute] on $_POST[day]-$_POST[month]-$_POST[year]";  
		 }
	   ?>

Recommended Answers

All 3 Replies

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.

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    
        $host="localhost"; // Host name

        $username="root"; // Mysql username

        $password="original"; // Mysql password

        $db_name="cutting_edge"; // Database name

        $tbl_name="appointment"; // Table name
        
        // Connect to server and select databse.

        mysql_connect("$host", "$username", "$password")or die("cannot connect");

        mysql_select_db("$db_name")or die("cannot select DB");



        if($_POST[ok])

        {

	  $date = "$_POST[day]-$_POST[month]-$_POST[year]";
          $name = $_POST['name'];
          $time = "$_POST[hour]:$_POST[minute]";
          $time1 = "$_POST[hour]:00";
          $time2 = "$_POST[hour]:30";
          
          // To protect MySQL injection (more detail about MySQL injection)

          $date = stripslashes($date);

          $name = stripslashes($name);

          $date = mysql_real_escape_string($date);

          $name = mysql_real_escape_string($name);
          $time = stripslashes($time);

          $time = mysql_real_escape_string($time);


         
          $sql="SELECT * FROM $tbl_name WHERE date='$date' and time='$time1'";
          $result=mysql_query($sql);
          if( $result == 0 ){
           
             $sql="SELECT * FROM $tbl_name WHERE date='$date' and time='$time2'";
             $result=mysql_query($sql);
             if($result == 0){
               $sql ="INSERT INTO appointment VALUES( '$date', '$time', '$name' )";
               mysql_query($sql);
             }

          }

         }

       ?>

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    
        $host="localhost"; // Host name

        $username="root"; // Mysql username

        $password="original"; // Mysql password

        $db_name="cutting_edge"; // Database name

        $tbl_name="appoint"; // Table name
        
        // Connect to server and select databse.

        mysql_connect("$host", "$username", "$password")or die("cannot connect");

        mysql_select_db("$db_name")or die("cannot select DB");



        if($_POST[ok])

        {

	  $date = "$_POST[month]-$_POST[day]-$_POST[year]";
          $name = $_POST['name'];
          $time = "$_POST[hour]:$_POST[minute]";
          $min = $_POST['minute'];
          
          if(($min != '00') || ($min != '30')){
            echo "Appointments are every 30 minutes please re-choose your time to accommodate this schedule";
            echo $min;
          }
          else{
            // To protect MySQL injection (more detail about MySQL injection)

            $date = stripslashes($date);

            $name = stripslashes($name);

            $date = mysql_real_escape_string($date);

            $name = mysql_real_escape_string($name);
            $time = stripslashes($time);

            $time = mysql_real_escape_string($time);



            $sql="SELECT * FROM $tbl_name WHERE date='$date' and time='$time'";
            $result=mysql_query($sql);
           
            $count=mysql_num_rows($result);
          
            if( $count == 0){
 
              $sql ="INSERT INTO appoint VALUES( '$date', '$time', '$name' )";
              mysql_query($sql);
               
              echo "$name, Scheduled an appointment for $time on $date";
             }
            else{
              echo "An Appointment Is already Scheduled for this time ";
              echo $time;
             }
           }
         }
?>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.