1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

expitation code

Discussion in 'PHP' started by ataloss, Dec 9, 2020.

  1. #1
    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):

     
    Last edited by a moderator: Dec 9, 2020
    ataloss, Dec 9, 2020 IP
  2. sarahk

    sarahk iTamer Staff

    Messages:
    28,494
    Likes Received:
    4,457
    Best Answers:
    123
    Trophy Points:
    665
    #2
    What errors are you getting?

    Why is your navigation in an iframe? you know you can just include the file, right?
     
    sarahk, Dec 9, 2020 IP
  3. malky66

    malky66 Acclaimed Member

    Messages:
    3,996
    Likes Received:
    2,248
    Best Answers:
    88
    Trophy Points:
    515
    #3
    You have an error on line 27, is that supposed to be commented out? That said, how old is that code? It looks ancient.
     
    malky66, Dec 9, 2020 IP
  4. sarahk

    sarahk iTamer Staff

    Messages:
    28,494
    Likes Received:
    4,457
    Best Answers:
    123
    Trophy Points:
    665
    #4
    Good point

    (PHP version 5.2.11)
    Code (markup):
    The errors might be as simple as deprecated code
     
    sarahk, Dec 9, 2020 IP
  5. malky66

    malky66 Acclaimed Member

    Messages:
    3,996
    Likes Received:
    2,248
    Best Answers:
    88
    Trophy Points:
    515
    #5
    lol, never noticed that.. 2009 when that version came out, that's like 100 years old in code age..:rolleyes:
     
    malky66, Dec 9, 2020 IP
    sarahk likes this.
  6. JEET

    JEET Notable Member

    Messages:
    3,825
    Likes Received:
    502
    Best Answers:
    19
    Trophy Points:
    265
    #6
    Comment this line, like below, put a double // before the word "if"

    //if today's date is greater than your expiration date
     
    JEET, Dec 10, 2020 IP
  7. malky66

    malky66 Acclaimed Member

    Messages:
    3,996
    Likes Received:
    2,248
    Best Answers:
    88
    Trophy Points:
    515
    #7
    Yeah pretty sure I already pointed that out....doesn't fix the outdated code though.
     
    malky66, Dec 11, 2020 IP
    JEET likes this.
  8. ataloss

    ataloss Active Member

    Messages:
    79
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #8
    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):
     
    Last edited by a moderator: Dec 15, 2020
    ataloss, Dec 15, 2020 IP
  9. sarahk

    sarahk iTamer Staff

    Messages:
    28,494
    Likes Received:
    4,457
    Best Answers:
    123
    Trophy Points:
    665
    #9
    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
    upload_2020-12-16_17-13-9.png
    so then, in your script you just need to look at the value of $row['diff'] rather than manipulate date variables.
     
    sarahk, Dec 15, 2020 IP