我创建了一个 CRON 作业,每天早上 8 点 30 分运行,以便将报告发送到特定的电子邮件地址。但是,该报告在用户输入特定日期的情况下起作用。我想知道如何将 $_post 值从开始和结束日期变量更改为“今天”和昨天的日期。
这是代码:
session_start();
$s = $_POST['$yesterday'];
$e = $_POST['$today'];
$i = $_SESSION['user'];
$m = "VACANCY APPLICATIONS REPORT FROM $s TO $e \r\n\r\n";
$conn = mysqli_connect("");
$em = "email address";
$vrquery = "SELECT jobid,role,jobtype,vacancyref FROM job ORDER BY jobid";
$vrresult = mysqli_query($conn, $vrquery);
while($vrrow=mysqli_fetch_array($vrresult))
{
$m = $m . $vrrow['vacancyref'] . " " . $vrrow['role'] . " " . $vrrow['jobtype'] . "\r\n\r\n";
$vquery = "SELECT cname,ctel,cemail FROM candidatejob,cv,candidate WHERE jobid=".$vrrow['jobid']." AND candidatejob.cvid=cv.cvid AND cv.cid=candidate.cid AND cvdate>='$s' AND cvdate<='$e' ORDER BY cname";
$vresult = mysqli_query($conn, $vquery);
while($vrow=mysqli_fetch_array($vresult))
{
$m = $m . $vrow['cname'] . " " . $vrow['ctel'] . " " . $vrow['cemail'] . "\r\n";
}
$m = $m . "\r\n\r\n";
}
$m = $m . "\r\n\r\nALL CANDIDATES SUBMITTING CVs WITHIN DATES\r\n\r\n";
$cvquery = "SELECT cname,ctel,cemail FROM cv,candidate WHERE cv.cid=candidate.cid AND cvdate>='$s' AND cvdate<='$e' ORDER BY cname";
$cvresult = mysqli_query($conn, $cvquery);
while($cvrow=mysqli_fetch_array($cvresult))
{
$m = $m . $cvrow['cname'] . " " . $cvrow['ctel'] . " " . $cvrow['cemail'] . "\r\n";
}
$conn->close();
$headers = "From: no-reply@nortech.org.uk\r\nX-Mailer: PHP/" . phpversion();
mail($em, " Daily Job Applications Report", $m, $headers);
?>
cron 作业效果很好,但它没有从数据库返回任何结果。我知道连接是正确的,因为它在我的所有页面上都是一样的,而且它们都可以工作。任何人都可以请帮助并提供有关为什么它没有从数据库中提取的建议吗?
非常感激