I am making a recurring event system and have to hard code a check to see if an event has passed to make a new one. (No, I can not make a cron job because the system base is Windows and no, I do not have access to the task scheduler.)
This is the code I have so far:
<?php
require('common.php');
$query = "SELECT
*
FROM
DD_events
";
try{
$stmt = $db->prepare($query);
$result = $stmt->execute();
}
catch(PDOException $ex){
die("Failed to run query: " . $ex->getMessage());
}
$chk = $stmt->fetchall();
//print_r($chk);
foreach ($chk as $chks) {
if (time() > $chks['event_date']) {
//Add 1 day to event time
$time = strtotime($chks['event_date']);
$newTime = $time + 86400; // 24 * 60 * 60
// Create query to make the next event
$query = "INSERT INTO
DD_events (event_name, event_date, initiator, min_lvl, max_level)
VALUES
({$chks['event_name']}, {$newTime}, 0, {$chks['min_lvl']}, {$chks['max_level']})
";
try
{
// These two statements run the query against your database table.
$stmt = $db->prepare($query);
$stmt->execute();
}
catch(PDOException $ex)
{
// Note: On a production website, you should not output $ex->getMessage().
// It may provide an attacker with helpful information about your code.
die("Failed to run query: " . $ex->getMessage());
}
}
}
it returns this error:
Failed to run query: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 200)' at line 4
Can anyone spot the error I am making because I have been looking at it for the past 30 mins and can’t see it.
Perhaps an easier way to do the same thing:
This will create a new event for each existing event one day later (which is what you said the code was supposed to do) and eliminates the need for basically your whole script