DaemonForums  

Go Back   DaemonForums > Miscellaneous > Programming

Programming C, bash, Python, Perl, PHP, Java, you name it.

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1   (View Single Post)  
Old 16th August 2008
cajunman4life cajunman4life is offline
Real Name: Aaron Graves
Package Pilot
 
Join Date: May 2008
Location: Coolidge, Arizona
Posts: 203
Thanked 16 Times in 14 Posts
Default PHP regular expression help

Hey guys, writing a regex for PHP to validate date input to be put in an entry in MySQL.

Format must be YYYY-MM-DD HH:MM:SS

I have this:

Code:
  $must_match = "^[0-9]{4}\-[0-9]{2}\-[0-9]{2}\ [0-9]{2}\:[0-9]{2}\:[0-9]{2}$";
  if(preg_match($must_match, $dte) && $dte) {
    if(!$dte) {
      $query = "INSERT INTO $table VALUES ('', NOW(), 'ajgraves', '$post');";
    } else {
      $query = "INSERT INTO $table VALUES ('', '$dte', 'ajgraves', '$post');";
    }
  } else {
    die("ERROR: You entered an invalid date");
  }
  mysql_query($query);
And no matter what I enter, it always fails. Any ideas?
__________________
I just saved a bunch of money on my car insurance by fleeing the scene of the accident!
Reply With Quote
 

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Regular expressions: renaming files with 'sed' J65nko Guides 26 15th October 2010 08:03 PM
perl expression syntax qsecofr Programming 3 16th February 2009 12:56 PM
Mount filesystem with a regular user ivanatora FreeBSD General 15 30th July 2008 08:51 AM
are you an former bsdforum regular? ephemera Off-Topic 18 28th July 2008 12:57 PM


All times are GMT. The time now is 09:40 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content copyright © 2007-2010, the authors
Daemon image copyright ©1988, Marshall Kirk McKusick