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"; }

?>

    None of your code is actually working, is it?

    mysql_fetch_array()
    

    isn't used with MySQLi.

    $row is never used.

    if(expiredate == expiredate - 7)
    

    will always be false, will cause warnings about undefined constants (and will be a fatal error in PHP 8).

    else (expiredate == expiredate - 1)
    { echo "<br/>1 week remaining"; }
    

    is a syntax error so the code would never even be run in the first place.

    Might I suggest fixing the problems you have to start with before you focus on creating new ones?

    Please use [code]...[/code] tags around your code.

      It looks like you willy-nilly mixed tutorials from PHP 5.x, PHP 7.x, and JavaScript.

      You're using $row before you define $row, and ... well, it's hard to read. In addition to Weedpacket's hint about using the code tags, please format your code in your IDE - it makes it a lot easier to see errors. For instance, I'm 99% sure your brackets are mismatched, but you can't easily tell.

        Write a Reply...