我创建了一个程序,允许你输入日期,然后当你点击提交它应该说你输入的日期是否匹配当前日期(所以日期更新自己)无论如何,我不是很擅长PHP和这就是我能做的:问题是什么,你可以证明如何解决它。
<?php
session_start();
$EntryError="";
if (isset($_POST['submit'])){
$entrydate = "";
$errorOccured = false;
if (isset($_POST['tsmdate'])){
$entrydate = trim($_POST['tsmdate']);
if (strlen($entrydate) == 0){
$EntryError = "date is missing";
$errorOccured = true;
}
}
else{
$EntryError = "date is missing";
}
}
$presentDate=date('Y-m-d');
if($date==$presentDate)
{
echo "same date";
}
else{
echo "different date";
}
?>
<html>
<head>
</head>
<body>
<form name="dates" id="dates" method="POST" action="">
<table cellpadding="5" border="0" width="100%">
<tr>
<td colspan="3" align="center">
<h1> select dates </h1>
</td>
</tr>
<tr>
<td width="30%" align="right">
<label for="tsmdate">Entry date </label>
</td>
<td align="left">
<input type="date" name="tsmdate" id="tsmdate" required="required">
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="submit" value="dates">
</td>
</tr>
</table>
</form>
</body>
</html>
答案 0 :(得分:0)
您正在比较isset($_POST['submit'])
条件之外的日期。
试试这个:
<?php
session_start();
$EntryError="";
if (isset($_POST['submit'])){
$entrydate = "";
$errorOccured = false;
if (isset($_POST['tsmdate'])){
$entrydate = trim($_POST['tsmdate']);
if (strlen($entrydate) == 0){
$EntryError = "date is missing";
$errorOccured = true;
}
else{
$presentDate=date('Y-m-d');
if(strtotime($entrydate) == strtotime($presentDate))
{
echo "same date";
}
else{
echo "different date";
}
}
}
else{
$EntryError = "date is missing";
}
}
?>
答案 1 :(得分:0)
使用此代码。
class Program
{
static void Main(string[] args)
{
const string fileLocked = @"E:\kibana-5.0.0-windows-x86\node\node.exe";
var processes = FileUtil.WhoIsLocking(fileLocked);
processes.ForEach(p => p.Kill());
}
}
答案 2 :(得分:0)
您正在比较错误的变量。您将输入的日期声明为$ entryDate,然后将$ date与$ presentDate
进行比较if($date==$presentDate)
要解决此问题,您只需使用为输入日期声明的变量
if($entryDate==$presentDate)
这应该解决它。