Re: new guy with stupid question

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

 



Hi,

Aaron helped me to understand the question so here's an add-in to his comment.

<?php

if ($_SERVER['REQUEST_METHOD'] === 'GET') {//'GET' !== 'get'
//display form (using POST method)
}
elseif ($_SERVER['REQUEST_METHOD'] === 'POST' &&
isset($_POST['_non-optional_fields_']) &&
is_numeric($_POST['_year_field_']) &&
is_numeric($_POST['_month_field_']) &&
is_numeric($_POST['_day_field_']) &&
checkdate($_POST['_month_field_'], $_POST['_day_field_'],
$_POST['_year_field_'])) {
//process the form
$date = $_POST['_year_field_'] . '-' . $_POST['_month_field_'] . '-' .
$_POST['_day_field_'];
$sqlInsertNewDate = "INSERT INTO table_name (date_field) VALUES ('" .
$date . "')";
}
else {
//some error message or redirection here
}

?>

from  the MySQL manual:

MySQL version through 4.1 accept certain "illegal" values for dates,
such as '1999-11-31'. This is useful when you want to store a possibly
incorrect value specified by a user (for example, in a web form) in
the database for future processing. MySQL verifies only that the month
is in the range from 0 to 12 and that the day is in the range from 0
to 31.

that's why checkdate() is important.

Hope it helped.

Balazs

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux