1

I am trying to add a year to a date going into a SQL database from PHP. I have tried DATEADD(Year,1,NOW()) And various other forms but can't seem to get it to add a year onto it in SQL.

<?php  

require ('includes/connect_db.php'); 

$q = "UPDATE users SET subdate = NOW() WHERE username = '{$_SESSION[username]}'";
$r = @mysqli_query ( $link, $q ) ;
# Close database connection.
# mysqli_close($link); 

?>

Thank you very very much!

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
  • to prevent **sql Injection** use always **prepared statements** with parameters see https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php – nbk Apr 17 '20 at 10:54

1 Answers1

3

You are attempting SQL Server syntax in MySQL.

In MySQL, you would simply do:

now() + interval 1 year

Or:

date_add(now(), interval 1 year)
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786