Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #1720

Re: problem saving date fields

From Jerry Stuckle <jstucklex@attglobal.net>
Newsgroups comp.lang.php
Subject Re: problem saving date fields
Date 2011-05-20 22:35 -0400
Organization A noiseless patient Spider
Message-ID <ir78cp$53s$1@dont-email.me> (permalink)
References <2407eb47-b406-432c-9aed-b76abc94aae9@z37g2000vbl.googlegroups.com> <hdqdt6t7376p18vh6jr8kdfrfgl9fn1iv2@4ax.com>

Show all headers | View raw


On 5/20/2011 6:58 PM, Jeff North wrote:
> On Fri, 20 May 2011 11:38:06 -0700 (PDT), in comp.lang.php Co
> <vonclausowitz@gmail.com>
> <2407eb47-b406-432c-9aed-b76abc94aae9@z37g2000vbl.googlegroups.com>
> wrote:
>
>> | Hi All,
>> |
>> | I have two date fields.
>> | When I change of them the other one gets set back to default:
>> | 00-00-0000
>> | I have to save both to make it work. Is there a solution for this?
>> |
>> | The arrival_date and departure_date are build up like this:
>> |
>> |<select name="arrival_day" class="formFields" id="arrival_day">
>> |<option value="<?php print "$arrival_day"; ?>"><?php print
>> | "$arrival_day"; ?></option>
>> |<option value="01">1</option>
>> |<option value="02">2</option>
>> |<option value="03">3</option>
>> |<option value="04">4</option>  etc......
>> |
>> |<select name="arrival_month" class="formFields" id="arrival_month">
>> |<option value="<?php print "$arrival_month"; ?>"><?php print
>> | "$arrival_month"; ?></option>
>> |<option value="01">January</option>
>> |<option value="02">February</option>
>> |<option value="03">March</option>
>> |<option value="04">April</option>  etc......
>> |
>> |<select name="arrival_year" class="formFields" id="arrival_year">
>> |<option value="<?php print "$arrival_year"; ?>"><?php print
>> | "$arrival_year"; ?></option>
>> |<option value="2011">2013</option>
>> |<option value="2011">2012</option>
>> |<option value="2011">2011</option>
>> |<option value="2010">2010</option>  etc......
>
> How are you setting the $arrival_* and $depature_* values?
>

 From the input - after is is sent from his form.

> If this is a new entry then all of the $arrival_* and $depature_* will
> be null or zero - therefore the select options will not be
> automatically selected (View Source of the page to see if there are
> any error messages within these lists).
>

No, because he isn't setting them until after the form has been 
displayed and the user has made his selection.

> You might want to initialise the values by:
> $arrival_day   = $depature_day   = date('j');
> $arrival_month = $depature_month = date('n');
> $arrival_year  = $depature_year  = date('Y');
>
> If you read a record from the database then you would over write the
> above values. This will ensure that correct values within the select
> lists are automatically selected.
>

No, it is NOT a good idea to add a row every time the page is displayed. 
  Wait for the user to respond to the request, then add it to the 
database, as he is already doing.

>> | The table is updated like this:
>> |
>> |     $arrival_month = preg_replace('#[^0-9]#i', '',
>> | $_POST['arrival_month']);
>> |     $arrival_day = preg_replace('#[^0-9]#i', '',
>> | $_POST['arrival_day']); // filter everything but numbers
>> | 	$arrival_year = preg_replace('#[^0-9]#i', '',
>> | $_POST['arrival_year']); // filter everything but numbers
>> |     $arrival_date = "$arrival_year-$arrival_month-$arrival_day";
>> |
>> |     $departure_month = preg_replace('#[^0-9]#i', '',
>> | $_POST['departure_month']);
>> |     $departure_day = preg_replace('#[^0-9]#i', '',
>> | $_POST['departure_day']); // filter everything but numbers
>> | 	$departure_year = preg_replace('#[^0-9]#i', '',
>> | $_POST['departure_year']); //
>> | 	$departure_date = "$departure_year-$departure_month-$departure_day";
>
> You are assuming that items within the listboxs have been selected
> (normally this the case only if the initial setup is correct).
> You should use
> $arrival_day = ( isset( $_POST['arrival_day'] ) ?
> intval($_POST['arrival_day']) : 0;
> if( $arrival_day == 0 ) { $pageError = "Invalid arrival day number";}
>
> I also assume that you are checking that you can't arrive before you
> depart :-)
>

He needs to do other validation on the data also, but first he needs to 
get this part working.

>> | 	$sqlUpdate = mysql_query("UPDATE myMembers SET
>> | firstname='$firstname', lastname='$lastname', gender='$gender',
>> | partner='$partner', country='$country', rank='$rank',
>> | service='$service', position='$position',
>> | arrival_date='$arrival_date',departure_date='$departure_date' WHERE
>> | id='$id' LIMIT 1");
>> |
>> | Is there a reason why this happens? I do create the right format to
>> | put the data back in the table.
>
> But are the values your setting the ones you expect?
>

That's why the suggestion to print the SQL statement he generated.

BTW - your sig separator is broken.  It needs to be exactly 
hyphen-hyphen-space-newline.

>
> -- --------------------------------------------------------------
> Anything But Marriage, perversely, turns one of the country's
> more culturally visible minorities into an advertisement for just
> how cool and successful life outside of wedlock can be.
>
> http://www.theatlantic.com/issues/2002/05/rauch.htm
> -- --------------------------------------------------------------


-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

problem saving date fields Co <vonclausowitz@gmail.com> - 2011-05-20 11:38 -0700
  Re: problem saving date fields Luuk <Luuk@invalid.lan> - 2011-05-20 20:50 +0200
  Re: problem saving date fields Jeff North <jnorthau@yahoo.com.au> - 2011-05-21 08:58 +1000
    Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-20 22:35 -0400
      Re: problem saving date fields Jeff North <jnorthau@yahoo.com.au> - 2011-05-21 13:13 +1000
        Re: problem saving date fields Co <vonclausowitz@gmail.com> - 2011-05-20 23:47 -0700
          Re: problem saving date fields Co <vonclausowitz@gmail.com> - 2011-05-21 00:18 -0700
            Re: problem saving date fields Luuk <Luuk@invalid.lan> - 2011-05-21 09:54 +0200
            Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-21 10:37 -0400
              Re: problem saving date fields Co <vonclausowitz@gmail.com> - 2011-05-21 08:07 -0700
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-21 19:55 -0400
                Re: problem saving date fields Co <vonclausowitz@gmail.com> - 2011-05-22 14:20 -0700
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-22 17:28 -0400
        Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-21 10:32 -0400
          Re: problem saving date fields Jeff North <jnorthau@yahoo.com.au> - 2011-05-22 02:08 +1000
            Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-21 20:01 -0400
              Re: problem saving date fields "Twayne" <nobody@devnull.spamcop.net> - 2011-05-21 20:30 -0400
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-21 23:13 -0400
              Re: problem saving date fields Jeff North <jnorthau@yahoo.com.au> - 2011-05-22 14:28 +1000
                Re: problem saving date fields Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-05-22 12:45 +0200
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-22 08:26 -0400
                Re: problem saving date fields "Twayne" <nobody@devnull.spamcop.net> - 2011-05-22 09:20 -0400
                Re: problem saving date fields Jeff North <jnorthau@yahoo.com.au> - 2011-05-23 00:08 +1000
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-22 13:47 -0400
                Re: problem saving date fields Bill B <me@privacy.net> - 2011-05-22 14:17 -0400
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-22 14:26 -0400
                Re: problem saving date fields Bill B <me@privacy.net> - 2011-05-22 16:27 -0400
                Re: problem saving date fields Jeff North <jnorthau@yahoo.com.au> - 2011-05-23 09:01 +1000
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-22 20:21 -0400
                Re: problem saving date fields Bill B <me@privacy.net> - 2011-05-22 21:36 -0400
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-22 21:46 -0400
                Re: problem saving date fields Jeff North <jnorthau@yahoo.com.au> - 2011-05-23 12:20 +1000
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-22 22:30 -0400
                Re: problem saving date fields Co <vonclausowitz@gmail.com> - 2011-05-22 21:51 -0700
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-23 07:13 -0400
                Re: problem saving date fields Co <vonclausowitz@gmail.com> - 2011-05-23 10:18 -0700
                Re: problem saving date fields Co <vonclausowitz@gmail.com> - 2011-05-23 10:27 -0700
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-23 14:16 -0400
                Re: problem saving date fields Co <vonclausowitz@gmail.com> - 2011-05-23 12:17 -0700
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-23 18:00 -0400
                Re: problem saving date fields Co <vonclausowitz@gmail.com> - 2011-05-23 22:30 -0700
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-24 05:45 -0400
                Re: problem saving date fields Co <vonclausowitz@gmail.com> - 2011-05-26 02:10 -0700
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-26 05:43 -0400
                Re: problem saving date fields Co <vonclausowitz@gmail.com> - 2011-05-23 14:26 -0700
                Re: problem saving date fields Jerry Stuckle <jstucklex@attglobal.net> - 2011-05-23 18:01 -0400
                Re: problem saving date fields Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2011-05-23 23:59 +0200
                Re: problem saving date fields "Twayne" <nobody@devnull.spamcop.net> - 2011-05-22 09:11 -0400

csiph-web