我试图在点击按钮时使用php更新mysql数据库中的时间。我使用以下查询:
update tableName SET Time=CURTIME() where Uname='$uname1' AND Password = '$password'
此查询无效。但如果我硬编码这个查询,这将工作正常。我不知道为什么它不起作用。这是我完整的PHP代码:
<?php
$host='localhost';
$uname='root';
$pwd='password';
$db='database';
$con=mysql_connect($host,$uname,$pwd) or die("Connection Failed");
mysql_select_db($db,$con) or die("database selection failed");
$uname1 = mysql_real_escape_string($_POST['Uname']); # Secure the input!
$password = mysql_real_escape_string($_POST['Password']);
$time = strtotime(exec("date"));
$flag['code']=0;
$select=("update Insert1 SET Time=CURTIME() where Uname='$uname1' AND BINARY Password = BINARY '$password'" );
//$select=("select * from Insert1 where Uname = '$uname1' AND BINARY Password = BINARY '$password'" );
$r=mysql_query($select,$con);
if(mysql_num_rows($r) > 0) {
$flag['code']=1;
}
print(json_encode($flag));
mysql_close($con);
?>
答案 0 :(得分:0)
您可以在更新查询中尝试使用“NOW()”而不是“CURTIME()”,如下所示:
$select=("update Insert1 SET Time=NOW() where Uname='$uname1' AND BINARY Password = BINARY '$password'" );