Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Problem setting Date field in MySQL

3 views
Skip to first unread message

Robert

unread,
May 25, 2012, 7:56:29 PM5/25/12
to
Hello,
I am having an issue with creating a database record and saving dates into the record. I have a form the user
enter's dates. That form calls the 'updateArticle.php' file and to update or create a new recod. Currently I'm
only working on the create record side of the program right now. All of the field's are passed from the form to
the PHP program throught the $_POST method. After that I assign the $_Post variable to a standard PHP variable,
then create the query and execute it on the database. When I look at the new record in the database, all dates are
set to '0000-00-00'. I've attempted to use the Date() function and change the format of the dates to 'Y-m-d',
however that does not work either. I've included the code below, if there is anything unclear or any help anyone
can provide, please feel free to ask or email me. I've been pulling my hair out tring to figure out where I've
screwed this up. Thanks!!!

FYI, $_POST['subDate'], $_POST['pubDate'] all echo out to 05-25-2012. The third date (remDate) is left blank on
purpose. The last echo result in the below code is:
INSERT INTO `ARTICLES`(`id`, `title`, `sub_date`, `pub_date`, `rem_date`, `body`, `imgname`) VALUES (NULL,'','05-
25-2012','05-25-2012','','',NULL)
1

============CODE==============
$id = sanitizeString($_POST['id']);
$title = sanitizeString($_POST['title']);
$subDate = sanitizeString($_POST['subDate']);
$pubDate = sanitizeString($_POST['pubDate']);
$remDate = sanitizeString($_POST['remDate']);
$body = sanitizeString($_POST['body']);
$imgFileName = sanitizeString($_POST['imgFileName']);
$query = "INSERT INTO `ARTICLES`(`id`, `title`, `sub_date`, `pub_date`, `rem_date`, `body`, `imgname`)
VALUES (NULL,'$title','$subDate','$pubDate','$remDate','$body',NULL)";
$results = mysql_query($query);
echo $query."<br />".$results;
remove the @@ and replace with OO to get my email address.

Thanks!!!

--
--------------------------------- --- -- -
Posted with NewsLeecher v3.9 Final
Web @ http://www.newsleecher.com/?usenet
------------------- ----- ---- -- -

Jerry Stuckle

unread,
May 25, 2012, 8:10:07 PM5/25/12
to
Echo the actual query you're sending to MySQL, then fix it.

And remember to check how MySQL requires dates to be entered (this is
the wrong newsgroup for that).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstu...@attglobal.net
==================

Jeff North

unread,
May 25, 2012, 11:16:37 PM5/25/12
to
On 25 May 2012 23:56:29 GMT, in comp.lang.php Robert
<m@@reservi...@gmail.com>
<4fc01c2d$0$1765$c3e8da3$66d3...@news.astraweb.com> wrote:

>| Hello,
>| I am having an issue with creating a database record and saving dates into the record. I have a form the user
>| enter's dates. That form calls the 'updateArticle.php' file and to update or create a new recod. Currently I'm
>| only working on the create record side of the program right now. All of the field's are passed from the form to
>| the PHP program throught the $_POST method. After that I assign the $_Post variable to a standard PHP variable,
>| then create the query and execute it on the database. When I look at the new record in the database, all dates are
>| set to '0000-00-00'. I've attempted to use the Date() function and change the format of the dates to 'Y-m-d',
>| however that does not work either. I've included the code below, if there is anything unclear or any help anyone
>| can provide, please feel free to ask or email me. I've been pulling my hair out tring to figure out where I've
>| screwed this up. Thanks!!!
>|
>| FYI, $_POST['subDate'], $_POST['pubDate'] all echo out to 05-25-2012. The third date (remDate) is left blank on
>| purpose. The last echo result in the below code is:
>| INSERT INTO `ARTICLES`(`id`, `title`, `sub_date`, `pub_date`, `rem_date`, `body`, `imgname`) VALUES (NULL,'','05-
>| 25-2012','05-25-2012','','',NULL)
>| 1

Your dates need to be in yyyy-mm-dd format

Robert

unread,
May 28, 2012, 8:35:31 AM5/28/12
to
Thanks for the info!! It helped alot.
Robert Moore
m@@reservi...@gmail.com

replace the @@ with OO to get my email address.

Thanks!!!

Captain Paralytic

unread,
May 30, 2012, 7:43:32 AM5/30/12
to
On May 26, 12:56 am, Robert <m@@reservices....@gmail.com> wrote:
> Hello,
>   I am having an issue with creating a database record and saving dates into the record. I have a form the user
> enter's dates.
Since when do plurals have an apostrophe?
> set to '0000-00-00'. I've attempted to use the Date() function and change the format of the dates to 'Y-m-d',
> however that does not work either.
"Does not work" is as useful as a description of what the problem is
as a chocolate teapot is to making tea. I would say that you most
likely didn't use it correctly, but since you haven't shown us what
you tried, we have no way to know.


> I've included the code below, if there is anything unclear or any help anyone
> can provide, please feel free to ask or email me. I've been pulling my hair out tring to figure out where I've
> screwed this up. Thanks!!!
You've included code that shows you trying to enter a non-ISO format
date into what we must assume is a date field and telling us that it
doesn't work. Not much help...
0 new messages