我只是想找出为什么我不断收到此错误:
Notice: Undefined variable: flsrfc
现在$ flsrfc设置如下:
if (date_create($flstart)) {
$flsdt = date_create($flstart);
if ($flsdt) {
$flsrfc = date_format($flsdt, "Y-m-d\TH:i");
} else {
$flsrfc = date_format(date_create(time()), "Y-m-d\TH:i");
}
}
现在,我遇到的问题是尝试使用我要获取的格式化时间来设置datetime-local输入。这是该代码以及错误说明其来源的代码。我的猜测是date_create函数无法正常工作,但我不知道为什么。
$HTMLOUT .= '<input name="fls" value="'.$flsrfc.'" size="30" type="datetime-local" />';
我确保$ flstart从数据库中获取数据,这是它的代码:
$flstart = mysqli_fetch_row(mysqli_query("SELECT value FROM config WHERE name = 'flstart'"))[0];
我已经阅读了许多关于php的手册页和文档,试图找出原因,我在时间戳上尝试了strtotime,不行,我还尝试将其强制转换为整数,也遇到了同样的问题。有人可以向我指出正确的方向吗?谢谢。
Your issue is that if
date_create
fails,$flsrfc
never gets set. You should rewrite that code as:Note that you can simplify the
else
portion by just callingdate
as its default input is the output oftime()
.In terms of why
date_create
is failing, that would depend on the format of the data in your table. If you are storing it as a MySQLdate
ordatetime
type, there should be no problem with it.