Jump to content

Recommended Posts

I'm trying to insert a future date in the mysql database.

Its not working right now.  The date field is type datetime.

here's the code:

if ($rememberMe=="on"){				
setcookie("nwo",$tempID, time()+3600*24*30);
mysql_query("INSERT INTO cookie (tempID, userID, expirationDate) 
VALUES ('$tempID', '$userID', NOW(),INTERVAL 30 DAY)");
}else{				
setcookie("nwo",$tempID, 0);
mysql_query("INSERT INTO cookie (tempID, userID, expirationDate) 
VALUES ('$tempID', '$userID', NOW(),INTERVAL 20 MINUTES)");
		}

 

Is that not correct syntax for the query?

Its not putting anything in the database.

I'm trying to insert 30 days from now in one, and 20 minutes from now in the other statement.

Link to comment
https://forums.phpfreaks.com/topic/132434-solved-help-inserting-a-future-date/
Share on other sites

Check this out

 

http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html

 

if ($rememberMe=="on"){            
   setcookie("nwo",$tempID, time()+3600*24*30);
   mysql_query("INSERT INTO cookie (tempID, userID, expirationDate)
   VALUES ('$tempID', '$userID', DATE_ADD(NOW(),INTERVAL 30 DAY))");
}else{            
   setcookie("nwo",$tempID, 0);
   mysql_query("INSERT INTO cookie (tempID, userID, expirationDate)
   VALUES ('$tempID', '$userID', DATE_ADD(NOW(),INTERVAL 20 MINUTES))");
         }

 

I believe you are missing the DATE_ADD function in your query.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.