Page 1 of 1
a small date problem php/mysql
Posted: Mon Jun 12, 2006 2:53 pm
by biggie
I have 3 selectes like:
<select name='day'><option value='1'>1<option value='2'>2<option .......<option value='31'>31
<select name='month'><option value='1'>1<option value='2'>2<option .......<option value='12'>12
<select name='year'><option value='1'>2005<option value='2'>2006
how can I save all these 3 under 1 variable to save it in mysql as a date?
I think you can all understand what I want to do...I want to have a select menu from which a user selects a day, a month and the year and all these 3 to be joined to form a date and save it in a date field in mysql
10x
Posted: Mon Jun 12, 2006 3:00 pm
by feyd
somename[day]
somename[month]
somename[year]
?
Posted: Mon Jun 12, 2006 4:13 pm
by biggie
can u be more explicit?
I have a field called "flight_day" in mysql...is date type...and I want the 3 selects to be saved together as a date in this field....how could I do it?
Posted: Mon Jun 12, 2006 4:23 pm
by RobertGonzalez
You should of course validate your posted data, but this is the gist of it.
Code: Select all
<?php
if ( isset($_POST['checkableformfield']) ) {
$year = $_POST['year'];
$month = $_POST['month'];
$day = $_POST['day'];
$date_to_enter = $year . '-' . $month . '-' . $day;
}
?>
10x
Posted: Tue Jun 13, 2006 10:46 am
by biggie
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
10x it worked just fine...one more question..off topic...can u tell me what does this next php file does?
global.inc.php
Code: Select all
<?php
function pt_register()
{
$num_args = func_num_args();
$vars = array();
if ($num_args >= 2) {
$method = strtoupper(func_get_arg(0));
if (($method != 'SESSION') && ($method != 'GET') && ($method != 'POST') && ($method != 'SERVER') && ($method != 'COOKIE') && ($method != 'ENV')) {
die('The first argument of pt_register must be one of the following: GET, POST, SESSION, SERVER, COOKIE, or ENV');
}
$varname = "HTTP_{$method}_VARS";
global ${$varname};
for ($i = 1; $i < $num_args; $i++) {
$parameter = func_get_arg($i);
if (isset(${$varname}[$parameter])) {
global $$parameter;
$$parameter = ${$varname}[$parameter];
}
}
} else {
die('You must specify at least two arguments');
}
}
?>
I don't understand what exactly it does..I got a php form generator and the process file includes this global.in.php file that I copied above...and I want to know what does it do?
feyd | Please use Code: Select all
and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
Posted: Tue Jun 13, 2006 12:01 pm
by RobertGonzalez
The function is taking a superglobal type along with a string of values and for that global and assigning those values to the superglobal. It is kinda of hacky, but it will do the trick. I will say that I am more inclined to use superglobals of a type that I am expecting ($_GET, $_POST, $_COOKIE, $_SESSION) rather than accept whatever can come by.
Posted: Tue Jun 13, 2006 12:07 pm
by bdlang
That function appears to be a backwards compatible (i.e. prior to
superglobals in v4.1) method to assign and create global scope to a variable named within. In other words, if you do something like
It will look at the value stored in
$HTTP_SESSION_VARS['userID'] and make a globally accessible variable
$userID with that stored value. It actually takes multiple arguments, therefore taking as many SESSION variables there might be and flooding the namespace with global variables.
I'd avoid using that code like the plague. For one, it relies on and creates global variables, which I can't stand. Secondly, it's outdated. You're better off accessing the
superglobals, i.e. $_POST, $_SESSION, etc.
Posted: Tue Jun 13, 2006 12:07 pm
by bdlang
Everah wrote:The function is taking a superglobal type along with a string of values and for that global and assigning those values to the superglobal. It is kinda of hacky, but it will do the trick. I will say that I am more inclined to use superglobals of a type that I am expecting ($_GET, $_POST, $_COOKIE, $_SESSION) rather than accept whatever can come by.
^ what he said.
Beat me to it.
