PHP-将今天的日期插入MySql字段无效


PHP- insert todays date into MySql field not working

对一些人来说很简单,但对PHP来说很陌生。我只想在MySQL 的日期字段中插入今天的日期

提前谢谢。

$sql = "UPDATE IA SET IASubmitted ='yes', IASubmittedDate='date('Y-m-d')' WHERE Reference='$Reference'";
$result=mysql_query($sql); 

我认为最简单的答案如下:

$sql = "UPDATE IA SET IASubmitted ='yes', IASubmittedDate='". date('Y-m-d'). "' WHERE Reference='$Reference'";
$result=mysql_query($sql); 

试试这个:

$date = date('Y-m-d');
sql = "UPDATE IA SET IASubmitted ='yes', IASubmittedDate='". $date. "' WHERE Reference='$Reference'";
$result=mysql_query($sql); 

希望这能对你有所帮助。

试试这个

sql = "UPDATE IA SET IASubmitted ='yes', IASubmittedDate='" DATE_FORMAT(NOW(),'%Y-%m-%d') "' WHERE Reference='$Reference'";
$result=mysql_query($sql);

您可以使用MySQLs CURDATE()函数在不使用php date()函数的情况下简单地执行此操作。这应该像这个

$sql = "UPDATE IA SET IASubmitted ='yes', IASubmittedDate=CURDATE() WHERE Reference='$Reference'";
$result=mysql_query($sql); 

您也可以使用:

$sql="UPDATE IA SET IASubmitted='yes',IASubmittedDate=now()WHERE Reference='$Reference'";$result=mysql_query($sql);

这将同时起作用:当IASubmittedDate是日期或IASubmittedDate是日期时间