Jump to content

[SOLVED] Setting curdate() as a variable


poleposters

Recommended Posts

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

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()

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.