这是整个代码。我包括整个事情,因为我不知道哪个部分导致日期设置为 1970-01-01。
<html>
<head>
<title>...</title>
<link rel="stylesheet" type="text/css" href="style.css"/>
<link rel="icon" href="images/opacIcon.ico" />
</head>
<body id="home">
<div id="date">
<?
date_default_timezone_set('.../...');
$today = date('Y-m-d');
echo "Today is $today";
?><br>
</div>
<div id="logoTop">
<img src = "images/....png" alt = "... logo here" width="355" />
</div>
<FORM method="post" id="form" action="Home.php">
<input type="submit" id="logoutBtn" name="submit" value="Home" style="cursor: pointer;"/><br>
</FORM>
<FORM method="post" id="form" action="Logout.php">
<input type="submit" id="logoutBtn" name="submit" value="Log Out" style="cursor: pointer;"/><br>
</FORM>
<div style="position: absolute; left:10em; top: 0em;">
<ul id="nav">
<li><a href="SysUsers.php">By Date</a></li>
<li><a href="UsersTableCourse.php">By Course</a></li>
<li><a href="UsersTableYr.php">By Year</a></li>
</ul>
<div id="search">
<div class="DropD">
<form method="post">
<select name="SYr">
<option value="">Please Select...</option>
<option value="1">First Year</option>
<option value="2">Second Year</option>
<option value="3">Third Year</option>
<option value="4">Fourth Year</option>
<option value="5">Fifth Year</option>
</select>
<input type="submit" id="Sbtn1" style="cursor: pointer;" name="search_projects" value="Search">
</form>
</div>
</div>
<div class="DDate">
<form method="post">
<input type="date" name="Date1" value="<?php echo $_POST['Date1'] ?>" style="position:absolute; top:2em; left:7em;">
<p style="font-family:Calibri; color:green; font-size:15px; position: absolute; top: 1em; left: 18em;">to</p>
<input type="date" name="Date2" value="<?php echo $_POST['Date2'] ?>" style="position:absolute; top:2em; left:23em;"><br />
</form>
</div>
</div>
<div class="scrollableTable">
<center><table class="font1" border="3px solid white" width="70%">
<thead>
<tr id="tblRow">
<th id="tblData" width="20%">Access Date</td>
<th id="tblData" width="15%">ID number</td>
<th id="tblData" width="35%">Name</td>
<th id="tblData" width="20%">Keyword</td>
</tr>
</thead>
<?php
if ( $_POST['search_projects'] ) {
$SYr = $_POST['SYr'];
$startDate = date("Y-m-d", strtotime( $_POST['Date1'] ) );
$endDate = date("Y-m-d", strtotime( $_POST['Date2'] ) );
$con = mysql_connect("...", "...", "...") or die ('Error: ' . mysql_error() );
mysql_select_db("...");
$sql = "SELECT * FROM statisticData WHERE SYear LIKE '$SYr' AND (accessDate BETWEEN '$startDate' AND '$endDate') ORDER BY accessDate DESC";
$result = mysql_query( $sql );
while ( $row = mysql_fetch_object( $result ) ) {
$Date = $row->accessDate;
$ID = $row->IDnum;
$Name = $row->Sname;
$Key = $row->keyWord;
echo "<tr>";
echo "<td>" . $Date. " </td>" . " <td>" . $ID. " </td>" . " <td>" . $Name. " </td>". " <td>" . $Key. " </td>";
echo "</tr>";
}
echo "</table>";
echo "</center>";
}
?>
</div>
</body>
</html>
我尝试删除要求用户设置日期范围的部分,我得到了正确的结果,其中包括以四年级学生身份登录的用户。然后我添加了日期范围来限制结果,但我什么也没得到。我回应了日期,发现它们设置在 Unix 纪元日期“1970-01-01”上。我怎样才能阻止这种情况发生?是否与转换有关。请不要介意我的代码对 sql 注入开放。我现在只需要得到正确的结果。