poleposters Posted September 9, 2009 Share Posted September 9, 2009 Hi. I want users to select a date for an entry. However if they fail to select a date, I want to insert the current date as default into the database. Heres my code. if(!empty($_POST['item_date'])) { $item_date=$_POST['item_date']; } else { $item_date="CURDATE()"; } It doesn't want to work. It sets the date to to 1970 instead. Can someone shed some light on what I'm doing wrong? Thanks/. Link to comment https://forums.phpfreaks.com/topic/173635-solved-setting-curdate-as-a-variable/ Share on other sites More sharing options...
Adam Posted September 9, 2009 Share Posted September 9, 2009 I assume the "$item_date" var is then passed through a query? Could you show us the code? Link to comment https://forums.phpfreaks.com/topic/173635-solved-setting-curdate-as-a-variable/#findComment-915273 Share on other sites More sharing options...
poleposters Posted September 9, 2009 Author Share Posted September 9, 2009 The query is as follows. $query="INSERT INTO press_releases (press_release_id,press_release_title,press_release,press_release_date) VALUES ('','$title','$press_release','$item_date')"; $result=mysql_query($query) or trigger_error("Query: $query\n<br />MySQL Error: " . mysql_error()); It works fine if I pick a date. And the query executes if I leave the date field blank. It just doesn't insert curdate() Link to comment https://forums.phpfreaks.com/topic/173635-solved-setting-curdate-as-a-variable/#findComment-915278 Share on other sites More sharing options...
poleposters Posted September 9, 2009 Author Share Posted September 9, 2009 I worked it out. I should of been using php's date() function instead. Link to comment https://forums.phpfreaks.com/topic/173635-solved-setting-curdate-as-a-variable/#findComment-915281 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.