PHP-将今天的日期插入到MySql字段中不起作用

PHP-将今天的日期插入到MySql字段中不起作用

问题描述:

Pretty simple to some people, but pretty new to PHP. I just want to insert today date into a date field in MySQL

Thanks in advance.

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

对某些人来说非常简单,但对PHP来说却很陌生。 我只想将今天的日期插入MySQL中的日期字段 p>

提前感谢。 p>

  $ sql =“UPDATE IA SET IASubmitted  ='是',IASubmittedDate ='date('Ym -d')'WHERE Reference ='$ Reference'“; 
 $ result = mysql_query($ sql);  
  code>  pre> 
  div>

I think the simplest answer is as follows:

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

try this :

$date = date('Y-m-d');

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

hope this can help you.

Try this

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

You can simply do this without the php date() function by using MySQLs CURDATE() function. This should look like this

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

You can also use:

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

This will work both: when IASubmittedDate is date or IASubmittedDate is datetime