0

I've written PHP code to set a deadline date by admin, so the admin enters the deadline date via form and it will store it in the database. Now I want to use this deadline to check whenever the user wants to access a page. If the deadline date expired the user can't access this page it will move them automatically to a page called "closed.html", if not the user can access it .. I've tried this code but it keeps moving me to closed.html page even when the date has not expired yet! Ideas please?

<?php
session_start();
$Load=$_SESSION['login_user'];
$sql= "Select deadline from schedule_deliverables";
$deadline = mysql_query($sql);
$todays_date = date("Y-m-d");

$today = strtotime($todays_date);
$expiration_date = strtotime($deadline);

if ($expiration_date > $today) {
     echo "<meta http-equiv='refresh' content='1;URL=Check_file.php'>"; //user can access the page 
} else {
     echo "<meta http-equiv='refresh' content='1;URL=closed.html'>"; //deadline is past user can't access 

}


?>
Jasperan
  • 2,154
  • 1
  • 16
  • 40
Anna Lord
  • 31
  • 1
  • 2
  • 3
  • And where exactly are you setting up your database connection? Just `mysql_query` won't cut it (and is also deprecated by the way, use mysqli or PDO instead, see [the manual](http://php.net/mysql_query) on mysql_query). Is this the complete code or did you leave out certain parts? – Oldskool Dec 17 '12 at 11:42
  • Please do not use `mysql_*` functions any more http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/12860140#12860140 – Bogdan Burym Dec 17 '12 at 12:07

1 Answers1

1

You need to fetch_Array

$query = "Select deadline from schedule_deliverables"; 

$result = mysql_query($query) or die(mysql_error());


$row = mysql_fetch_array($result) or die(mysql_error());
$deadline = $row['deadline']; // and then you rest code with that if
pregmatch
  • 2,629
  • 6
  • 31
  • 68
  • +1 this should be correct. And I would like to add, limiting the query by adding `LIMIT 1` (mysql) or `TOP 1` (tsql) (or a plausible where clause) to really only get one result – Najzero Dec 17 '12 at 11:44