Potatis Posted January 31, 2008 Share Posted January 31, 2008 I am having trouble searching for information that will help me query a my table's datetime column to check whether the current time is earlier or later than the time in the database. What I am trying to do is have a date and time in the database submitted by an admin, which represents the expiry time for submitting a form to a contest. When a user submits the form, I want to compare the time the form is submitted with the deadline time in the database. I don't want to submit the time from the form into the database. I keep finding all this information about timestamps, but I don't want the form to even send if the expiry date has passed. I want it to just redirect. Should the entry form have a hidden value that sends the time as NOW() and on the processing page I set that as a variable such as $now=NOW() , query and select the datetime row from the database and as test is NOW()>= row['time']? Or am I on the wrong track? I'm way too embarassed to post the code I have been trying, since I am not very proficient yet with PHP. Usually I try to modify scripts I search for to fit what I am trying to do, but with this I can't find an example that applies to me so I tried doing it from scratch which I knew would fail. Quote Link to comment https://forums.phpfreaks.com/topic/88671-solved-datetime-for-submit-expiry/ Share on other sites More sharing options...
irvieto Posted January 31, 2008 Share Posted January 31, 2008 Why not to make a small code in the form page to check if the form should be viewable or not? By doing that, you are preventing users to access the form and redirecting them.. something like this. <?php $sql = "select 1 from some_table where id_form='x' and valid_date=curdate()"; // In case of a 1 day form; ///bla bla.. if( $num_rows>0 ){ //date is ok, show the form, } else { header("Location:other_page.html"); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/88671-solved-datetime-for-submit-expiry/#findComment-454128 Share on other sites More sharing options...
Potatis Posted January 31, 2008 Author Share Posted January 31, 2008 Ah, ok I see what you are suggesting. valid_date=curdate() , Does that mean to the end of today's date, ie. midnight? If so, how could I set a specific time for it to expire, such as 7.30pm? I'd like the form to be up for about a week, so I need to have it expire on a set day and time. I could give the form an id as you suggest, and do an if( $num_rows>0 ) on it, but I need to have valid_date equal the time in the database. I'll play around, thanks for the tip. Quote Link to comment https://forums.phpfreaks.com/topic/88671-solved-datetime-for-submit-expiry/#findComment-454185 Share on other sites More sharing options...
Potatis Posted January 31, 2008 Author Share Posted January 31, 2008 I know how to do it now. When the time passes, the link no longer works and the page redirects. For those who are curious, here is the code: <?php $timezone= (date_default_timezone_set("Australia/Sydney")); $today = mktime(); $expires = mktime( 23, 53, 0, 01, 31, 2008); if ($today < $expires) { header("Location: http://www.domain.com"); } else { echo "Page has expired."; } ?> The code is on it's own page, between the page with the link, and the linked page. Quote Link to comment https://forums.phpfreaks.com/topic/88671-solved-datetime-for-submit-expiry/#findComment-454278 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.