c# - PHP SQL Get Date Time from Username and compare to todays date

Solution:

First of all, you should be using prepared statements. If you want to use mysqli then I show you how to do it below, but I would strongly recommend learning PDO instead.

You can check DateTime objects against themselves. No need to use the old strtotime() function. You just need to select the single value from the database.

<?php

mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$con = mysqli_connect("server", "name", "pass", "db");

$HWID = "";
if (!empty($_POST['HWID'])) {
    $HWID = $_POST['HWID'];
} elseif (!empty($_GET['HWID'])) {
    $HWID = $_GET['HWID'];
} else {
    die("nodata");
}

$stmt = $con->prepare("SELECT Expire_Date FROM users WHERE HWID=?");
$stmt->bind_param('s', $HWID);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_object();
$Expire_Date = $row->Expire_Date;

if (new DateTime() > new DateTime($Expire_Date)) {
    die("valid");
} else {
    die("invalid");
}

Answer

Solution:

As El_Vanja say, your problem is the strtotime($rows). When you fetch your rows with $rows=mysql_fetch_array($result); you get an array with all selected columns(see doc here, you should take care it's depreciated since PHP 5.5 and remove from PHP 7.0 and above). When you read the doc of strtotime your first argument must be a string.

To fix your error you just have to replace $rows=mysql_fetch_array($result); by $rows=mysql_fetch_array($result[0]); or $rows=mysql_fetch_array($result["HWID"]);. Personnaly I prefer the second one is more readable.

Source