Re: updating date field

From: Date: Mon, 20 Nov 2006 23:58:40 +0000
Subject: Re: updating date field
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-42703@lists.php.net to get a copy of this message
<code> if (isset($_POST['eMonth']) && $_POST['eMonth'] != '') $eMonth = $_POST['eMonth']; else $eMonth = '01';
                                    
if (isset($_POST['eDay']) && $_POST['eDay'] != '')
            $eMonth = $_POST['eDay'];
else $eMonth = '01';
                                    
if (isset($_POST['eYear']) && $_POST['eYear'] != '')
            $eYear = $_POST['eYear'];
else $eYear = '2007';
Can I suggest the use of curly braces? It's much easier to read: if (isset($_POST['eYear']) && $_POST['eYear'] != '') {
    $eYear = (int)$_POST['eYear'];
} else {
    $eYear = '2007';
}
$updateEventQuery = "UPDATE events SET EventDate = '$eYear-$eMonth-$eDay', AppliedFYE = '$appliedFYE', LocationID = '$eLocation', StartTime = '$eHour:$eMin $eAMPM', Type = '$eType', Format = '$eFormat', Description = '$eDescription', EventApproved = '$eApproved', EventOfficial = '$eOfficial', LastUpdateBy = '".$_SESSION['ContactID']."' WHERE EventID = '".$_GET['eventid']."'";
You have sql injection bugs waiting to happen here. make sure the eventid is an integer at least: ..." . (int)$_GET['eventid'] . "'"; And I also suggest reading up about escaping strings (http://php.net/mysql_real_escape_string & http://php.net/mysql_escape_string). Of course you might have taken all that out to post an easier example, if that's the case then ignore those comments ;)
UPDATE events SET EventDate = '2006-10-10', AppliedFYE = '2007', LocationID = '14', StartTime = '5:00 PM', Type = '3', Format = 'BOARD', Description = 'Regular board meeting', EventApproved = '1', EventOfficial = '0', LastUpdateBy = '209' WHERE EventID = '54' When this query is actually run on the DB though, it queries with no errors, and all the data is saved/updated properly *except* the date - it becomes 0000-00-00.
I was going to suggest it's an invalid date-format but that looks fine. What is eventdate? a date field, a timestamp, other ? -- Postgresql & php tutorials http://www.designmagick.com/

« previous php.db (#42703) next »