| | |
Search File to see if appointment already exists for 30 min intervals
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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)
<?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]"; } ?>
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.
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.
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)
<?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 Syntax (Toggle Plain Text)
<?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; } } } ?>
![]() |
Other Threads in the PHP Forum
- Previous Thread: turn this array into a form
- Next Thread: Time in php?
| Thread Tools | Search this Thread |
ajax apache api array basics beginner binary broken cakephp checkbox class cms code codingproblem combobox cron curl database date display domain dynamic echo email error file files folder form format forms function functions google href htaccess html image include insert interactive ip java javascript joomla js limit link load login mail malfunctioning menu mlm mobile multiple mysql nodes oop outofmemmory paging parse paypal pdf php problem procedure query radio ram random recursion reference remote return script search server sessions sms source space sql syntax system table tutorial unset up-to-date update upload url validation validator variable video web webapplications websitecontactform youtube






