PHP / PDO insert current date plus one month in MYSQL

I am trying to add the current date (not the time if I have the option), as well as the date of the month later, in my MYSQL database, and I keep getting the following error:

Parse error: syntax error, unexpected T_LNUMBER in *myfile* on line 45 

My function for inserting data is as follows:

 function add_zipcode($zip, $adminID, $email) { global $db; $query = ' INSERT INTO zip_owners (zip, email, adminID, started, transferred, expires) VALUES (:zip, :email, :adminID, :started, :transferred, :expires)'; try{ $statement = $db->prepare($query); $statement->bindValue(':zip', $zip); $statement->bindValue(':email', $email); $statement->bindValue(':adminID', $adminID); $statement->bindValue(':started', now()); $statement->bindValue(':transferred', now()); $statement->bindValue(':expires', DATE_ADD(now(), INTERVAL 1 MONTH)); $statement->execute(); $statement->closeCursor(); } catch (PDOexception $e) { $error_message = $e->getMessage(); echo "<p>Database Error: $error_message </p>"; exit(); } } 

The problem is this:

 $statement->bindValue(':expires', DATE_ADD(now(), INTERVAL 1 MONTH)); 

I'm not quite sure why this syntax is not working.

My goal is to be able to compare dates when selecting rows to return rows that expire within a week of the current date.

0
source share
1 answer

To quote my MySQL statements, they are strings in PHP:

 $statement->bindValue(':expires', 'DATE_ADD(now(), INTERVAL 1 MONTH)'); 
+6
source

All Articles