intermittent failure of php date
am 18.01.2010 16:23:04 von John Corry
--0016363b954a00e750047d71ee10
Content-Type: text/plain; charset=ISO-8859-1
I maintain a site that is generating some strange behavior...
It's a custom built event registration app.
Events have event_dates that are stored in the MySQL db.
This code retrieves the event title and event date for display on the
registration acknowledgment page:
$q2 = "SELECT title, event_date, DATE_FORMAT(event_date, '%M %d, %Y') AS
formatted_event_date FROM events WHERE id =" . $eid . ";";
$result = mysql_query($q2);
if ($result) {
$row = mysql_fetch_array($result);
$title = $row['title'];
if(strtotime($row['event_date'])) {
$event_date = date("F m, Y", strtotime($row['event_date']));
} else {
$event_date = $row['formatted_event_date'];
}
Sometimes, it doesn't work.
Every 3rd or 4th registration notification email comes through with an empty
value for event_date.
There are no other references to the variable $event_date.
It works most of the time.
There's no pattern I can see. I even tried to force it to show a date by
selecting a formatted date and displaying that if the original programmer's
strtotime failed.
Where do you look for help with intermittent failures of a date field in the
DB?
--
John Corry
PHP developer - 3by400, Inc
http://www.3by400.com
--0016363b954a00e750047d71ee10--
Re: intermittent failure of php date
am 18.01.2010 16:32:49 von John Corry
--0016e659f46edcc61d047d721079
Content-Type: text/plain; charset=ISO-8859-1
The field in the DB is defined as type date.
I've had several event registrations for an upcoming event come through. THe
event date is '2010-01-27'.
2 of the 5 event registrations contained empty values for the date.
wtf?
On Mon, Jan 18, 2010 at 10:23 AM, John Corry wrote:
> I maintain a site that is generating some strange behavior...
>
> It's a custom built event registration app.
>
> Events have event_dates that are stored in the MySQL db.
>
> This code retrieves the event title and event date for display on the
> registration acknowledgment page:
>
> $q2 = "SELECT title, event_date, DATE_FORMAT(event_date, '%M %d, %Y') AS
> formatted_event_date FROM events WHERE id =" . $eid . ";";
> $result = mysql_query($q2);
> if ($result) {
> $row = mysql_fetch_array($result);
> $title = $row['title'];
>
> if(strtotime($row['event_date'])) {
> $event_date = date("F m, Y", strtotime($row['event_date']));
> } else {
> $event_date = $row['formatted_event_date'];
> }
>
> Sometimes, it doesn't work.
>
> Every 3rd or 4th registration notification email comes through with an
> empty value for event_date.
>
> There are no other references to the variable $event_date.
>
> It works most of the time.
>
> There's no pattern I can see. I even tried to force it to show a date by
> selecting a formatted date and displaying that if the original programmer's
> strtotime failed.
>
> Where do you look for help with intermittent failures of a date field in
> the DB?
>
>
> --
> John Corry
> PHP developer - 3by400, Inc
> http://www.3by400.com
>
>
--
John Corry
PHP developer - 3by400, Inc
http://www.3by400.com
--0016e659f46edcc61d047d721079--
Re: Re: intermittent failure of php date
am 18.01.2010 16:45:44 von Ashley Sheridan
--=-dOh7nse9M6cnNJvNz49a
Content-Type: text/plain
Content-Transfer-Encoding: 7bit
On Mon, 2010-01-18 at 10:32 -0500, John Corry wrote:
> The field in the DB is defined as type date.
>
> I've had several event registrations for an upcoming event come through. THe
> event date is '2010-01-27'.
>
> 2 of the 5 event registrations contained empty values for the date.
>
> wtf?
>
> On Mon, Jan 18, 2010 at 10:23 AM, John Corry wrote:
>
> > I maintain a site that is generating some strange behavior...
> >
> > It's a custom built event registration app.
> >
> > Events have event_dates that are stored in the MySQL db.
> >
> > This code retrieves the event title and event date for display on the
> > registration acknowledgment page:
> >
> > $q2 = "SELECT title, event_date, DATE_FORMAT(event_date, '%M %d, %Y') AS
> > formatted_event_date FROM events WHERE id =" . $eid . ";";
> > $result = mysql_query($q2);
> > if ($result) {
> > $row = mysql_fetch_array($result);
> > $title = $row['title'];
> >
> > if(strtotime($row['event_date'])) {
> > $event_date = date("F m, Y", strtotime($row['event_date']));
> > } else {
> > $event_date = $row['formatted_event_date'];
> > }
> >
> > Sometimes, it doesn't work.
> >
> > Every 3rd or 4th registration notification email comes through with an
> > empty value for event_date.
> >
> > There are no other references to the variable $event_date.
> >
> > It works most of the time.
> >
> > There's no pattern I can see. I even tried to force it to show a date by
> > selecting a formatted date and displaying that if the original programmer's
> > strtotime failed.
> >
> > Where do you look for help with intermittent failures of a date field in
> > the DB?
> >
> >
> > --
> > John Corry
> > PHP developer - 3by400, Inc
> > http://www.3by400.com
> >
> >
>
>
This sounds more like a problem with the code that is inserting the data
than the code that is retrieving it. A database should just lose data
randomly from fields unless you've got a really serious problem with
your computer system.
Are you sanitising the data that is being entered by people on the site?
If you don't force them to enter a date, then they might not enter one
at all, leading a null value or empty string to be entered into the date
field instead of a valid date.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--=-dOh7nse9M6cnNJvNz49a--