Jump to content

Recommended Posts

i have an if stmt that checks if an end datetime the user selected is ealier than now. if it is it will say that the event has already ended and they need to fix their date & time. for most computers it works great. but the comp im on now at work will say the event has already ended. however on the page i echo the current datetime and its grabbing the correct time...does anyone know what could possibly be happenning?

Link to comment
https://forums.phpfreaks.com/topic/151950-time-problem/
Share on other sites

heres the whole thing...its super messy..filled with a bunch of variables that i was testing that don't get used so i need to go back and clean it up but if you can help that would be MUCH appreciated.

<?php

/* File: checkpost.php*/

include("caneck.inc");

session_start();

if (@$_SESSION['auth'] != "yes")
{
   header("Location: /test/register_form.php");
   exit();
   }
if(!isset($_SESSION['logname']))
{
   header("Location: /test/register_form.php");
   exit();
   }

function clean_post($variable)
{
include("caneck.inc");
   $cxn = mysqli_connect($host,$user,$passwd,$dbname) or die("Couldn't connect"); 
   return mysqli_real_escape_string($cxn, strip_tags($variable));
}
//format dates
$_SESSION['starts'] = $_POST['syear']."-".$_POST['smonth']."-".$_POST['sday']."- ".$_POST['shour'].":".$_POST['sminute'].":00";

$_SESSION['ends'] = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']."- ".$_POST['ehour'].":".$_POST['eminute'].":00";


  
$_SESSION['title'] = clean_post($_POST['title']);
$_SESSION['description'] = clean_post($_POST['description']);
$_SESSION['event'] = clean_post($_POST['event']);
$_SESSION['location'] = clean_post($_POST['location']);
$_SESSION['created'] = date("Y-m-d h:i:s");



//add 12 to the hours if pm was selected

if($_POST['sampm'] == 'pm')
   {
     $shour = $_POST['shour'] + 12;

     $_SESSION['starts'] = $_POST['syear']."-".$_POST['smonth']."-".$_POST['sday']."- ".$shour.":".$_POST['sminute'].":00";
     $strt = gmmktime($shour+ 5, $_POST['sminute'],0, $_POST['smonth'], $_POST['sday'], $_POST['syear']);
   }
   else
   {
   $strt = gmmktime($_POST['shour']+ 5, $_POST['sminute'],0, $_POST['smonth'], $_POST['sday'], $_POST['syear']);
   }

$_SESSION['sampm'] = $_POST['sampm'];



$begin = $_POST['smonth']."/".$_POST['sday']."/".$_POST['syear']."&nbsp&nbsp&nbsp" .$_POST['shour'].":".$_POST['sminute']."&nbsp" .$_SESSION['sampm'];

$tt = mktime($_POST['ehour'], $_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']);

if($_POST['eampm'] == 'pm' and $_POST['ehour'] !==12)
   {
     $ehour = $_POST['ehour'] + 12;

     $_SESSION['ends'] = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']."-".$ehour.":".$_POST['eminute'].":00";
      $end = mktime($ehour, $_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']);
   }
   else
   {
   $ehour = 23;
   $end = mktime($ehour, $_POST['eminute'],0, $_POST['emonth'], $_POST['eday'], $_POST['eyear']);
   }


$_SESSION['eampm'] = $_POST['eampm'];

$finish = $_POST['emonth']."/".$_POST['eday']."/".$_POST['eyear']."&nbsp&nbsp&nbsp" .$_POST['ehour'].":".$_POST['eminute']."&nbsp" .$_SESSION['eampm'];



/*check for blanks*/


foreach($_POST as $field => $value)
{
  if($value == "")
$message = "Please fill in all blanks.<br>";
}

//if message is set, stop and display errors
if(isset($message))
   {
   extract($_POST);
   include("testdis.php");
   exit();
   }

//make sure dates exist

if(checkdate($_POST['smonth'],$_POST['sday'],$_POST['syear']))
  {  
  } 
else
  {
  $message .= "Your start date doesn't exist.<br>";
  }

//if message is set, stop and display errors
if(isset($message))
   {
   extract($_POST);
   include("testdis.php");
   exit();
   }
   
if(checkdate($_POST['emonth'],$_POST['eday'],$_POST['eyear']))
  {  
  } 
else
  {
  $message .= "Your end date doesn't exist.<br>";
  }

//if message is set, stop and display errors
if(isset($message))
   {
   extract($_POST);
   include("testdis.php");
   exit();
   }  

  if($strt >= $tt)
{
$message .="Your event ends before it starts.<br>";
}

//if message is set, stop and display errors
if(isset($message))
   {
   extract($_POST);
   include("testdis.php");
   exit();
   } 


$now = time();
$bb = date('F j, Y    g:i a',$end);
if($tt <= $now )
{
$message .="Your event has already ended.<br>";
}


//if message is set, stop and display errors
if(isset($message))
   {
   extract($_POST);
   include("testdis.php");
   exit();
   }
   
//enter in db
$today = date("Y-m-d H:i:s");

$cxn = mysqli_connect($host,$user,$passwd,$dbname)
         or die("Couldn't connect"); 

$sql = "INSERT INTO test (title, description,location, event, created, start, end, createdby)
VALUES ('{$_SESSION['title']}','{$_SESSION['description']}','{$_SESSION['location']}'
         ,'{$_SESSION['event']}','{$today}', '{$_SESSION['starts']}', '{$_SESSION['ends']}', '{$_SESSION['logname']}')";

$result = mysqli_query($cxn,$sql)
         or die ("Couldn't execute query.");  
   header("location: project12.php");

?>

Link to comment
https://forums.phpfreaks.com/topic/151950-time-problem/#findComment-797948
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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