我有这个,但不知道如何才能显示当前日期。我也知道这需要修复,所以它不会得到SQL注入。任何人都知道如何才能显示记录的当前日期。
$sql = "SELECT id, lanId, name, department, manager, request, request_description, request_comments, status, comments, compUser, compDt FROM requests WHERE status='Completed' AND compUser='xgrh'CURDATE()";
$results = mysql_query($sql) or die(mysql_error());
这是在我的管理页面上
<tr>
<td style="width: 125px"><a href="xgrhCompleted.php" target="Frame">xgrh</a></td>
<td style="width: 125px" align="center"><a href="xgrhCompleted.php" target="Frame"><?php $result = mysql_query("SELECT COUNT(*) FROM requests WHERE status='Completed' AND compUser='xgrh'");
while($row=mysql_fetch_array($result))
{
echo $row['COUNT(*)'];
} ?></a></td>
</tr>
答案 0 :(得分:0)
我这样做:
在查询前使用整个字符串设置变量
$user = 'xgrh'.Date('m/d/y');
<强>查询:强>
$sql = "SELECT id, lanId, name, department, manager, request, request_description, request_comments, status, comments, compUser, compDt FROM requests WHERE status='Completed' AND compUser='$user'";
你需要确定你的日期列的确切使用日期格式是什么(前导零或没有的天数,前导零或无前导的月份)并根据变量设置日期格式。
如果查询应该与您上次评论中的内容相同:
$date = Date('m/d/y');
$sql = "SELECT id, lanId, name, department, manager, request, request_description, request_comments, status, comments, compUser, compDt FROM requsts WHERE status='Completed' AND compUser='xgrh' AND compDT = '$date'";
此:
<tr>
<td style="width: 125px"><a href="xgrhCompleted.php" target="Frame">xgrh</a></td>
<td style="width: 125px" align="center"><a href="xgrhCompleted.php" target="Frame"><?php $result = mysql_query("SELECT COUNT(*) FROM requests WHERE status='Completed' AND compUser='xgrh'");
while($row=mysql_fetch_array($result))
{
echo $row['COUNT(*)'];
} ?></a></td>
</tr>
完全错了。你想要
a) run a query
b) echo the result
你完全混合了东西