【发布时间】:2018-02-23 00:16:52
【问题描述】:
我认为我的查询有问题。我无法获得我想要的正确功能。
示例场景:
如果我今天记录了产前检查,则在接下来的 30 天或一个月后,添加按钮将不会出现。
但是今天加上checkup后这个查询,第二天,add按钮就已经出现了。
这是我的代码:
$dateToday = date('Y-m-d');
$checkPatients = $conn->query("SELECT last_checkup FROM `prenatal_checkup` WHERE itr_no = '$_GET[id]' limit 1");
$fetchPatients = $checkPatients->fetch_array();
if($fetchPatients['last_checkup'] >= (date('m', strtotime('+1 month')) . '/01/' . date('Y', strtotime('+1 month')))){
echo '<div class="alert alert-danger" role="alert" style="font-weight: bold; margin-bottom:-13px;"><p>
'.ucfirst($_GET['firstname'])." ".ucfirst($_GET['lastname']). ' was already estimated her date of confinement.
Adding new data will be available again after one month. Please click the record below to proceed to next check up.</p></div>';
}
else
{
?>
<button class = "btn btn-primary" id = "show_com"><i class = "glyphicon glyphicon-plus">ADD</i></button>
<?php
}
【问题讨论】:
-
请注意,您的查询不安全,因为您直接向其提供用户提供的数据 (
$_GET)。请使用占位符实现 mysqli 准备好的语句。您似乎正在进行日期字符串比较,但m-d-Y可能无法可靠地作为字符串进行比较。 -
$fetchPatients['edc']中有什么 -
@RiggsFolly 这是患者的预计分娩日期
-
我不完全确定我喜欢你从哪里得到这个:stackoverflow.com/questions/13422032/get-1st-day-of-next-month 但我确实喜欢你在问之前做了研究。考虑到年份翻转,这看起来更可靠:3v4l.org/gMJQu
-
@TechieMickey 我认为 RiggsFolly 要求您确认您的
edc值也是m-d-Y格式。如果没有,我们需要知道它是什么格式。
标签: php