nepeaNMedia Posted March 10, 2008 Share Posted March 10, 2008 Hi Folks What I want to do is add a date to a table via user input form. If the user does NOT enter a date the variable needs to hold the value of mysql NOW(). I have this code; if(strlen($_POST['expiryDate'])>3){ $expDat = $_POST['expiryDate']; }else{ $expDat = 'NOW()'; } However, when I write $expDat into the query it doe not generate the NOW() value that typing NOW() directly into the query would produce any ideas cheers in anticipation paul Link to comment https://forums.phpfreaks.com/topic/95435-variable-to-hold-now-funtion/ Share on other sites More sharing options...
revraz Posted March 10, 2008 Share Posted March 10, 2008 NOW is MySQL, not PHP. Just set the default Field paramter for that column to NOW so if nothing passes to it, NOW is the default. Link to comment https://forums.phpfreaks.com/topic/95435-variable-to-hold-now-funtion/#findComment-488571 Share on other sites More sharing options...
nepeaNMedia Posted March 10, 2008 Author Share Posted March 10, 2008 Clever - at 2 am in the morning I did not think of that - thanks Link to comment https://forums.phpfreaks.com/topic/95435-variable-to-hold-now-funtion/#findComment-488573 Share on other sites More sharing options...
nepeaNMedia Posted March 10, 2008 Author Share Posted March 10, 2008 However I seem NOT to be able to set a value of NOW() directly into the table - it reports an error. Does it need to be storeds as timestamp as opposed to date? Link to comment https://forums.phpfreaks.com/topic/95435-variable-to-hold-now-funtion/#findComment-488580 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.