Jump to content

Help with program


thedigitale

Recommended Posts

Hey guys, I'm working with a calendar program and trying to disallow duplicate entries at the same time. I can't seem to get it to work. Right now 2 appointments can be posted at the same time. Any thoughts?

Thanks.

 

if ($_POST["date_add"]) {
			if ($_POST["all_day_add"] == "all") {
				$_POST["start_time_add"] = "12:00 am";
				$_POST["end_time_add"] = "11:59 pm";
			} else if ($_POST["all_day_add"] == "tba") {
				$_POST["start_time_add"] = "12:00 am";
				$_POST["end_time_add"] = "12:00 am";
			}
			if (!ereg ("([0-9]{1,2})[\/-]+([0-9]{1,2})[\/-]+([0-9]{4})",$_POST["date_add"],$date)) {
				$msg .= "Bad Date:".$_POST["date_add"];
			} else {
				if (!eregi ("([0-9]{1,2})[0-9]{2})[ ]?([a|p]m)",$_POST["start_time_add"],$start_time)) {
					$msg .= "Bad Start Time:".$_POST["start_time_add"];
				} else {
					if (($_POST["end_time_add"])&&(!eregi ("([0-9]{1,2})[0-9]{2})[ ]?([a|p]m)",$_POST["end_time_add"],$end_time))) {
						$msg .= "Bad End Time:".$_POST["end_time_add"];
					} else {
						if (strlen($date[1]) == 1) $date[1] = "0".$date[1];
						if (strlen($date[2]) == 1) $date[2] = "0".$date[2];
						if ((eregi("am",$start_time[3])) && ($start_time[1] == 12)) $start_time[1] = $start_time[1] - 12;
						if ((eregi("am",$end_time[3])) && ($end_time[1] == 12)) $end_time[1] = $end_time[1] - 12;
						if ((eregi("pm",$start_time[3])) && ($start_time[1] < 12)) $start_time[1] = $start_time[1] + 12;
						if ((eregi("pm",$end_time[3])) && ($end_time[1] < 12)) $end_time[1] = $end_time[1] + 12;
						if (strlen($start_time[1]) == 1) $start_time[1] = "0".$start_time[1];
						if (strlen($end_time[1]) == 1) $end_time[1] = "0".$end_time[1];

						$start_date = $date[3]."-".$date[1]."-".$date[2]." ".$start_time[1].":".$start_time[2];
						if ($_POST["end_time_add"]) {
							$hidden_end=$end_time[1]+1;
							$end_date = $date[3]."-".$date[1]."-".$date[2]." ".$hidden_end.":".$end_time[2];
							if (($end_time[1].$end_time[2]) >= ($start_time[1].$start_time[2])) {
									$q = "INSERT into ".$table_prefix."dates (event_id, date, end_date) values (".$event_id.", '".$start_date."', '".$end_date."')";
								} else {
									$q = "INSERT into ".$table_prefix."dates (event_id, date) values (".$event_id.", '".$start_date."')";
								}
						} else {
							$q = "INSERT into ".$table_prefix."dates (event_id, date) values (".$event_id.", '".$start_date."')";
						}
						$dup_query="SELECT * FROM `dates`";
						$dup_result=@mysql_query($dup_query);
						while($dup_row=@mysql_fetch_array($dup_result)){
							if ($start_date==$dup_row[1]){
								$msg.='This time is already booked';
							} else {
								$query = mysql_query($q);
							}
						}

						if (!$query) $msg .= 'There was an error creating a new event. You may have been locked out for non payment. If you are paid in full, please try again.';#"Database Error : ".$q;
					}
				}
			}
		}

Link to comment
https://forums.phpfreaks.com/topic/52799-help-with-program/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.