Can someone advise me as to why this doesn't work. It is code to advise a contract has expired. ====================================================================== code follows: --------------------------------------- <?php error_reporting(E_ALL); // show all errors - server configured at 6135, increases to 6143 (PHP version 5.2.11) -- // comment this line out when LIVE ini_set('display_errors','On'); // turn on error display -- comment this line out when LIVE $contract_expiration = '2020-12-31'; // set expiration date in YYYY-MM-DD format $days_remaining = round( (( strtotime($contract_expiration) - strtotime(date('Y-m-d')) ) / (60*60*24)) ); // computes days remaining -- (60s*60m*24h) represents 1 day if ($days_remaining < 31) { $contract_expiration_formatted = date('n/j/y',strtotime($contract_expiration)); // formats expiration date as M/D/YY if ($days_remaining == 7) $GLOBALS['contract_status'] = 'expires in a week!'; // alert message for contracts expiring today elseif ($days_remaining == 1) $GLOBALS['contract_status'] = 'expires tomorrow!'; // alert message for contracts expiring tomorrow else $GLOBALS['contract_status'] = 'expires in '.$days_remaining.' days - on '.$contract_expiration_formatted; // alert message for contracts expiring in 2-30 days } else $GLOBALS['contract_status'] = 'is current'; // contract period is beyond 30 days // ============================= blows up here ================================== if (date('Y-m-d') > $contract_expiration) { if today's date is greater than your expiration date header("location:expired-page.html"); echo "We're sorry but your contract has expired. Contact us immediately at [EMAIL]myguitarz781@gmail.com[/EMAIL] "; // a status alert message or you can populate with a web document exit; // kills the script and prevents the parser from rendering your web application below } else { ?> <HTML> <HEAD> </head> <body> <iframe src="nav.html" width="100%" height="30" style="height:1.8em scrolling="no" marginwidth="0" marginheight="0" border: none;> </iframe> <br> <iframe src="info.html" width="100%" height="60" style="height:1.8em scrolling="no" marginwidth="0" marginheight="0" border: none;> </iframe> <?=$GLOBALS['expiration_status'];?> </html> <?php } ?> ========================================== result follows: --------------------- $contract_expiration) { if today's date is greater than your expiration date header ("location:expired-page.html"); echo "We're sorry but your contract has expired. // a status alert message or you can populate with a web document exit; // kills the script and prevents the parser from rendering your web application below } else { ?> Code (php):
What errors are you getting? Why is your navigation in an iframe? you know you can just include the file, right?
You have an error on line 27, is that supposed to be commented out? That said, how old is that code? It looks ancient.
Comment this line, like below, put a double // before the word "if" //if today's date is greater than your expiration date
Hi, still fumbling. I have records in a database with an expiration field in DATE format. I want to display messages according to how long to expiration. please, someone, check my code. thanks. <?php $servername = "localhost"; $username = "root"; $password = ""; $dbname = "homedb"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $id=$row['id']; $password=$row['password']; $expiredate=$row['expiredate']; while($row=mysql_fetch_array($result)) { if(expiredate == expiredate - 7) echo "<br/>1 week remaining"; } else (expiredate == expiredate - 1) { echo "<br/>1 week remaining"; } else (expiredate == today()); { echo "<br/>we're sorry, your contract has expired"; } ?> Code (php):
In your if query you're comparing expiredate with itself which makes no sense. I'd expect you to have a variable called $now which is a date object. However, decades ago a colleague drummed into me that it's best to let the database do what databases do. Here's a query I just ran on one of my systems SELECT `calldate`, COUNT(`id`), DATEDIFF(NOW(), `calldate`) AS `diff` FROM `calls` GROUP BY `calldate` ORDER BY `calldate` DESC Code (SQL): when I run that I get this so then, in your script you just need to look at the value of $row['diff'] rather than manipulate date variables.