Jump to content

Datetime messing up


Ninjakreborn

Recommended Posts

The datetime is messing up. On entry it works fine, on edit it messes up.

My field is this:

news_date datetime No None

 

The code I am using for entry is the same for both add/edit. For adding it works fine, for editing it messes up the date and returns it to all 0's (month, year, day, and time).

	$news_id          = $_POST['news_id'];
	$news_date        = strtotime($_POST['news_date']);
	$news_date        = date('Y-m-d', $news_date);
	$news_description = $_POST['news_description'];
	echo $news_date;
	$error = '';

	if ($news_id == '') {
		$error .= 'News ID required.<br />';
	}
	if ($news_date == '') {
		$error .= 'News Date is required.<br />';
	}
	if ($news_description == '') {
		$error .= 'News Description is required.<br />';
	}

	if ($error == '') {
		$message = '';
		if ($news_id == 0) {
			$sql = "INSERT INTO recent_news (news_date, news_description) VALUES ('" . mysql_real_escape_string($news_date) . "','" . mysql_real_escape_string($news_description) . "')";
			if (mysql_query($sql)) {
				$message .= 'News item added successfully.<br />';
			}else {
				$message .= 'News item was NOT added. There was an internal error.<br />';
			}
		}else {
			$sql = "UPDATE recent_news SET news_date = '" . mysql_real_escape_string($news_date) . "' AND news_description = '" . mysql_real_escape_string($news_description) . "' WHERE news_id = '" . mysql_real_escape_string($news_id) . "'";
			if (mysql_query($sql)) {
				$message .= 'News item was edited successfully.<br />';
			}else {
				$message .= 'News item was NOT edited successfully.  There was an internal error.<br />';
			}
		}

When I echo the date, it returns the exact same whether adding/editing so I know it's getting entered into the database the exact same.

 

Thanks.

Link to comment
Share on other sites

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.