Cant get dates from a dropdown into my DB

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

User avatar
amp
New php-forum User
New php-forum User
Posts: 15
Joined: Tue Apr 01, 2003 3:12 am
Location: Ireland
Contact:

Cant get dates from a dropdown into my DB

Postby amp » Tue Apr 08, 2003 10:43 am

I'm trying to display multiple dropdown menus on a form so users can choose dates & I want to write the dates to the database. I've serached on how to do this & this is the only thing I could find

Code: Select all

function WriteDateSelect($BeginYear = 2002,
                         $EndYear = 2010,
                         $IsPosted = true,
                         $Prefix = '')
                     #    $Prefix = 'end1')
{
  if (! $BeginYear)
  {
    $BeginYear = date('Y');
  }

  if (! $EndYear)
  {
    $EndYear = $BeginYear;
  }

  $Year = $IsPosted
         ? (int) $_POST[$Prefix . 'Year']
          : (int) $_GET[$Prefix . 'Year'];
  $Month = $IsPosted
          ? (int) $_POST[$Prefix . 'Month']
          : (int) $_GET[$Prefix . 'Month'];
  $Day = $IsPosted
          ? (int) $_POST[$Prefix . 'Day']
          : (int) $_GET[$Prefix . 'Day'];

  echo '<select name="', $Prefix, 'Year">
         ';

 for ($i = $BeginYear; $i <= $EndYear; $i++)
  {
    echo '<option ';

    if ($i == $Year)
      echo 'selected="yes"';

   echo '>', $i, '</option>
        ';
  }

  echo '</select>-
        <select name="', $Prefix, 'Month">
          ';

  for ($i = 1; $i <= 12; $i++)
  {
    echo '<option ';

    if ($i == $Month)
      echo 'selected="yes"';

    echo '>', $i, '</option>
         ';
  }

  echo '</select>-
        <select name="', $Prefix, 'Day">
          ';

  for ($i = 1; $i <= 31; $i++)
  {
  echo '<option ';

    if ($i == $Day)
      echo 'selected="yes"';

    echo '>', $i, '</option>
         ';
  }

  echo '</select>
       ';
  return;
}

And this

Code: Select all

function GetDateSelectString($IsPosted = true,
                            $Prefix = '')
{
  if ($IsPosted)
  {
    return (int) $_POST[$Prefix . 'Year']
          . '-' . (int) $_POST[$Prefix . 'Month']
          . '-' . (int) $_POST[$Prefix . 'Day'];
  }

  return (int) $_GET[$Prefix . 'Year']
         . '-' . (int) $_GET[$Prefix . 'Month']
         . '-' . (int) $_GET[$Prefix . 'Day'];
}

about halfway down my form I call the GetDateSelectString function & it displays the dropdown menu, here is the code from my form that calls it

Code: Select all

WriteDateSelect(2003, 2010, true, 'begin1');

begin1 is a field in my table & is also in my script that processes the form but the date never goes into the database using this function.

I'm still a big time newbie so I don't even know if I'm using the function correctly, I got it here if anyone wants to take a look at it http://www.evolt.org/article/Using_PHP_ ... /20/33733/

Or if anyone else has any suggestions for date dropdowns please tell me :wink:

Thanks in advance for any replies.

Romantik
New php-forum User
New php-forum User
Posts: 67
Joined: Mon Feb 24, 2003 2:55 am
Location: ../Ukraine/Kherson
Contact:

Postby Romantik » Tue Apr 08, 2003 9:52 pm

echo '<select name="'. $Year.'"> ';

etc
You must have YYYY-MM-DD format in your DateBase
View source code in your browser
<select name="2003">


Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest