Dealing with Dates

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • ccarpenter@hillcountry.org

    Dealing with Dates

    (This has been posted on the PHP.general group also.)

    I'm writing an app where I want the user to be able to change a date on
    a record. Date field is 'TngDate'. I can pull the record from the
    mySql database, split it into day/month/year, put each in a drop down
    box. What I can't seem to do is collect the modified entries,
    reassemble them into a single variable and pass it on to the update
    script. I admit to being a newbie at this and most of my scripts
    (including this one) come from examples that I have found either on the
    'Net or in books. The script below is the script I have so far.
    It's in an include file. I would appreciate any help.

    <?php
    $monthName = array(1=> "January", "February", "March", "April", "May",
    "June", "July", "August", "September" , "October", "November",
    "December") ; $f_today = $formValues["TngDate"]; echo $f_today;

    /* create form containing date selection list */
    echo "<form method='post'>\ n";

    /* build selection list for the month */
    $todayMO = substr($f_today ,5,2);
    echo "<select name='dateMO'>\ n";
    for ($n=1;$n<=12;$n ++)
    {
    echo "<option value=$n\n";
    if ($todayMO == $n)
    {
    echo " selected";
    }
    echo "> $monthName[$n]\n";
    }
    echo "</select>";

    /* build selection list for the day */
    $todayDay = substr($f_today , 8,2);
    echo "<select name='dateDay'> \n";
    for ($n=1;$n<=31;$n ++)
    {
    echo "<option value=$n\n";
    if ($todayDay == $n)
    {
    echo " selected";
    }
    echo "> $n\n";
    }
    echo "</select>\n";

    /* build selection list for the year */
    $startYr = substr($f_today , 0,4);
    echo "<select name='dateYr'>\ n";
    for ($n=$startYr;$n <=$startYr+3;$n ++)
    {
    echo "<option value=$n\n";
    if ($startYr == $n)
    {
    echo " selected";
    }
    echo "> $n\n";
    }
    $newDate=date(" Y-m-d", mktime(0,0,0, $todayMO, $todayDay, $startYr));
    echo "</select>"; $newTngDate = strtotime("$new Date"); echo
    "</form>\n"; ?>

  • Andy Barfield

    #2
    Re: Dealing with Dates

    ccarpenter@hill country.org wrote:
    [color=blue]
    > (This has been posted on the PHP.general group also.)
    >
    > I'm writing an app where I want the user to be able to change a date on
    > a record. Date field is 'TngDate'. I can pull the record from the
    > mySql database, split it into day/month/year, put each in a drop down
    > box. What I can't seem to do is collect the modified entries,
    > reassemble them into a single variable and pass it on to the update
    > script. I admit to being a newbie at this and most of my scripts
    > (including this one) come from examples that I have found either on the
    > 'Net or in books. The script below is the script I have so far.
    > It's in an include file. I would appreciate any help.[/color]

    You need a form action, otherwise the form is posted nowhere:
    <form method='post' action='somescr ipt.php' name='something '>
    If the form is supposed to process it's own data, use
    $_SERVER['PHP_SELF'] to make the script action itself.

    Before you close the form, you need a submit button like
    <input type='submit' value='Submit' name='submit'>

    Your receiving script should look for the values in the predefined
    variable array $_POST - check the manual at www.php.net for more
    information.

    [color=blue]
    > /* create form containing date selection list */
    > echo "<form method='post'>\ n";[/color]
    This has no action

    [color=blue]
    > /* build selection list for the month */
    > $todayMO = substr($f_today ,5,2);
    > echo "<select name='dateMO'>\ n";
    > for ($n=1;$n<=12;$n ++)
    > {
    > echo "<option value=$n\n";
    > if ($todayMO == $n)
    > {
    > echo " selected";
    > }
    > echo "> $monthName[$n]\n";
    > }
    > echo "</select>";[/color]
    This simply gives a drop down list of months..... it will allow the use
    to select from that list. The other option lists have been removed for
    clarity.

    [color=blue]
    > $newDate=date(" Y-m-d", mktime(0,0,0, $todayMO, $todayDay, $startYr));
    > echo "</select>"; $newTngDate = strtotime("$new Date"); echo
    > "</form>\n"; ?>[/color]
    You are doing nothing with this at all, except echo-ing the closing form
    tag - you need to be able to submit the data that your user has changed.

    when you have posted the data, your receiving script will be able to
    find them. The server (where PHP works) is not aware of any changes
    until they have been submitted.

    HTH, regards,

    Andy

    Comment

    Working...