Hello.
I am currently making a php game for a bit of fun but I have got stuck at one point. I am trying to create a cron job that runs a function which updates the database. Below I have posted bits of the code.
Function
function aircraftdelivery($day, $month, $year, $delivery_day, $delivery_month, $delivery_year) {
if ($day == "$delivery_day" && $month == "$delivery_month" && $year == "$delivery_year") {
return ($delivered = ("UPDATE Aircraft SET Delivered = 'Yes' WHERE Delivery_Day = '" . $day . "'"));
}
}
Cron Job
<?
include("include/db.php");
include("include/config.php");
include("include/functions.php");
?>
<?
$query = ("SELECT * FROM Date");
$row = (mysql_fetch_array(mysql_query($query)));
$day = $row['Day'];
$month = $row['Month'];
$year = $row['Year'];
$query2 = ("SELECT * FROM Aircraft");
$row2 = (mysql_fetch_array(mysql_query($query2)));
$delivery_day = $row2['Delivery_Day'];
$delivery_month = $row2['Delivery_Month'];
$delivery_year = $row2['Delivery_Year'];
?>
<?
$date = gamedate($day, $month, $year);
$delivered = aircraftdelivery($day, $month, $year, $delivery_day, $delivery_month, $delivery_year);
?>
<?
mysql_query($date);
mysql_query($delivered);
?>
The $date mysql query updates the date in the database every minute and its stored by day, month and year. The $delivered query is trying to update a field in another table if the date of the game is the same as that in the table where the other field is.
It is not working for some reason.
It works if you enter the date numbers into the variables rather than getting them from the database. I am wondering if its missing the date. But not sure.
Any help would be much appreciated.
Ryan