a small date problem php/mysql

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
biggie
Forum Newbie
Posts: 8
Joined: Fri May 26, 2006 11:57 pm

a small date problem php/mysql

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

somename[day]
somename[month]
somename[year]
biggie
Forum Newbie
Posts: 8
Joined: Fri May 26, 2006 11:57 pm

?

Post 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?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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;
}
?>
biggie
Forum Newbie
Posts: 8
Joined: Fri May 26, 2006 11:57 pm

10x

Post by biggie »

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.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

,

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]
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post 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

Code: Select all

pt_register('SESSION', 'userID');
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.
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post 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. ;)
Post Reply