user3301611
user3301611

Reputation: 79

PHP- insert todays date into MySql field not working

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); 

Upvotes: 2

Views: 87

Answers (5)

Andrzej Reduta
Andrzej Reduta

Reputation: 767

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

Upvotes: 0

andyredfern
andyredfern

Reputation: 81

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); 

Upvotes: 4

dibi
dibi

Reputation: 3275

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); 

Upvotes: 0

Ullas
Ullas

Reputation: 11556

Try this

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

Upvotes: 0

user3454436
user3454436

Reputation: 231

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.

Upvotes: 0

Related Questions