Ninjakreborn Posted August 22, 2011 Share Posted August 22, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/245421-datetime-messing-up/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 22, 2011 Share Posted August 22, 2011 AND is a logical operator. You are trying to SET news_date to 'a date' AND'ed with the value in the news_description column. That would result in a TRUE value, which is an invalid DATE, so your news_date column is set to an all zero date value. Quote Link to comment https://forums.phpfreaks.com/topic/245421-datetime-messing-up/#findComment-1260502 Share on other sites More sharing options...
Ninjakreborn Posted August 22, 2011 Author Share Posted August 22, 2011 Ah good point. I forgot to split them with comma's. Thanks man. Quote Link to comment https://forums.phpfreaks.com/topic/245421-datetime-messing-up/#findComment-1260512 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.