0

i've write a php code to set a deadline date by admin , so the admin enter the daedline date via form and it will store in the database , now i want to use this deadline to check whenever the user want to access a page , if the deadline date expired the user can't access this page it will move him automatically to page called " closed.html" , if not the user can access it .. i've tried this code but it keep move me to closed.html page even when the date 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 

}


?>
Anna Lord
  • 21
  • 1
  • 1
  • 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,465
  • 5
  • 27
  • 63
  • +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