matt.sisto Posted May 2, 2009 Share Posted May 2, 2009 Hello. I am trying to create the $end_time, and $end_date, depending on the the $unit value multiplied by the selected $quantity. I am clearly doing something very wrong because the script is not even working. <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $unit = $_POST['unit']; $service = $_POST['service']; $quantity = $_POST['quantity']; $con_id1 = $_POST['con_id1']; $con_id2 = $_POST['con_id2']; $con_id3 = $_POST['con_id3']; $client_id = session_id(); $extra_info = $_POST['extra_info']; $start_time_hr = $_POST['start_time_hr']; $start_time_min = $_POST['start_time_min']; $time_sec = '00'; $month = $_POST["month"]; $day = $_POST["day"]; $year = $_POST["year"]; $event_start = $year."-".$month."-".$day." ".$_POST["event_start"]; $start_time = $start_time_hr.":".$start_time_min.":".$time_sec." ".$_POST["start_time"]; if (unit=='hour'){ $end_time = $start_time + ($quantity x 60,60).$_POST['end_time']; $event_end = $event_start.$_POST['event_end']; } else(unit=='day'){ $event_end = $event_start + ($quantity x 24,60,60).$_POST['$event_end']; $end_time = $start_time.$_POST['end_time']; } $sql = "INSERT INTO calendar_events VALUES (0,'".$event_start."','".$event_end."','".$client_id."','".$service."','".$unit."','".$quantity."','".$start_time."','".$end_time."','".$con_id1."','".$con_id2."','".$con_id3."','".$extra_info."')"; echo $sql; $result = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); header("Location: bookingform.php"); exit(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Book</title> </head> <body> </body> </html> appreciate any help. Link to comment https://forums.phpfreaks.com/topic/156544-creating-an-enddate-by-adding-units-to-the-startdate/ Share on other sites More sharing options...
matt.sisto Posted May 2, 2009 Author Share Posted May 2, 2009 I have since made some modifications to the script having realized a couple of errors, but still no joy. ??? <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $unit = $_POST['unit']; $service = $_POST['service']; $quantity = $_POST['quantity']; $con_id1 = $_POST['con_id1']; $con_id2 = $_POST['con_id2']; $con_id3 = $_POST['con_id3']; $client_id = session_id(); $extra_info = $_POST['extra_info']; $start_time_hr = $_POST['start_time_hr']; $start_time_min = $_POST['start_time_min']; $time_sec = '00'; $month = $_POST["month"]; $day = $_POST["day"]; $year = $_POST["year"]; $event_start = $year."-".$month."-".$day." ".$_POST["event_start"]; $start_time = $start_time_hr.":".$start_time_min.":".$time_sec." ".$_POST["start_time"]; if (unit=='hour'){ $end_time = $start_time + ($quantity * (60*60)).$_POST['end_time']; $event_end = $event_start.$_POST['event_end']; } else(unit=='day'){ $event_end = $event_start + ($quantity * (24*60*60)).$_POST['$event_end']; $end_time = $start_time.$_POST['end_time']; } $sql = "INSERT INTO calendar_events VALUES (0,'".$event_start."','".$event_end."','".$client_id."','".$service."','".$unit."','".$quantity."','".$start_time."','".$end_time."','".$con_id1."','".$con_id2."','".$con_id3."','".$extra_info."')"; echo $sql; $result = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); header("Location: bookingform.php"); exit(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Book</title> </head> <body> </body> </html> Link to comment https://forums.phpfreaks.com/topic/156544-creating-an-enddate-by-adding-units-to-the-startdate/#findComment-824279 Share on other sites More sharing options...
matt.sisto Posted May 2, 2009 Author Share Posted May 2, 2009 Does anybody know how I can get this working? if ($unit=='hour'){ $end_time = $start_time + ($quantity * (60*60)); $event_end = $event_start; $event_end=$_POST['$event_end']; $end_time = $start_time; $end_time=$_POST['$end_time']; } else($unit=='day'){ $event_end = $event_start + ($quantity * ((60*60)*24)); $event_end=$_POST['$event_end']; $end_time = $start_time; $end_time=$_POST['$end_time']; } Appreciate any help. Link to comment https://forums.phpfreaks.com/topic/156544-creating-an-enddate-by-adding-units-to-the-startdate/#findComment-824290 Share on other sites More sharing options...
matt.sisto Posted May 2, 2009 Author Share Posted May 2, 2009 So I have now modified the script which at least working however both the $end_time, $event_end variables are empty, so my if statement is not working. Any help appreciated <?php session_start(); if (!isset($_SESSION['username'])) { header("Location: login.php"); exit(); } require "dbconn2.php"; $unit = $_POST['unit']; $service = $_POST['service']; $quantity = $_POST['quantity']; $con_id1 = $_POST['con_id1']; $con_id2 = $_POST['con_id2']; $con_id3 = $_POST['con_id3']; $client_id = session_id(); $extra_info = $_POST['extra_info']; $start_time_hr = $_POST['start_time_hr']; $start_time_min = $_POST['start_time_min']; $time_sec = '00'; $address_first_line = $_POST['address_first_line']; $post_code = $_POST['post_code']; $country = $_POST['country']; $month = $_POST["month"]; $day = $_POST["day"]; $year = $_POST["year"]; $event_start = $year."-".$month."-".$day." ".$_POST["event_start"]; $start_time = $start_time_hr.":".$start_time_min.":".$time_sec." ".$_POST["start_time"]; if ($unit=='Hour'){ $end_time = ($start_time + ($quantity * (60*60))); $event_end = '$event_start'; } else{ $event_end = ($event_start + ($quantity * ((60*60)*24))); $end_time = '$start_time'; } $end_time=$_POST['$end_time']; $event_end=$_POST['$event_end']; $sql = "INSERT INTO calendar_events VALUES (0,'".$event_start."','".$event_end."','".$client_id."','".$service."','".$unit."','".$quantity."','".$start_time."','".$end_time."','".$con_id1."','".$con_id2."','".$con_id3."','".$address_first_line."','".$post_code."','".$country."','".$extra_info."')"; echo $sql; $result = mysql_query ($sql, $connection) or die ("Couldn't perform query $sql <br />".mysql_error()); header("Location: bookingform.php"); exit(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Book</title> </head> <body> </body> </html> Link to comment https://forums.phpfreaks.com/topic/156544-creating-an-enddate-by-adding-units-to-the-startdate/#findComment-824302 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.