Re: Re: intermittent failure of php date

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <jcorry.lists@xxxxxxxxx> 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



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux