a small date problem php/mysql
Moderator: General Moderators
a small date problem php/mysql
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
<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
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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
feyd | Please use
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
,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.phpCode: 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
,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]- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
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.
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.
Code: Select all
pt_register('SESSION', 'userID');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.
^ what he said.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.
Beat me to it.