I did not fully understand your question, but I tried to make a proper script that best matches your question. Simply foreach SQL result it will calculate the difference between the time stored in your DB and the current time. If the time in your DB is less than 30 days it will execute the code. I can't use less than or equal to 30 as some months have 30 days and it will return as a 1 month format instead of a 30 days.
Hope this helps...
<?php
$servername = "localhost";
$username = "username";
$password = "password";
try {
$conn = new PDO("mysql:host=$servername;dbname=myDB", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully";
}
catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
// Sanitize $_GET
$GET = filter_var_array($_GET, FILTER_SANITIZE_STRING);
$expiry_date = htmlspecialchars($GET['expiration_date'], ENT_QUOTES, 'UTF-8');
$stmt = $conn->prepare("SELECT * FROM domains");
$stmt->execute();
foreach($stmt as $row){
// Enter your DB row name corresponding with the expiry date
$dbexpiry_date = $row[''];
// Enter your timezone
date_default_timezone_set('Country/City');
$current_time = date('Y-m-d H:i:s');
// Calculating the difference
$dbTime = new DateTime($dbexpiry_date);
$currTime = new DateTime($current_time);
$interval = $currTime->diff($dbTime);
$days = $interval->format('%d');
$months = $interval->format('%m');
$years = $interval->format('%Y');
if($years == 0) {
if($months == 0) {
if($days < 30) {
// Enter your code here
execute "ticket-create.php";
} else {
die();
}
} else {
die();
}
} else {
die();
}
}
?>