FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » problem saving date fields
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: problem saving date fields [message #174084 is a reply to message #174081] Sat, 21 May 2011 07:54 Go to previous messageGo to previous message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma:
Senior Member
On 21-05-2011 09:18, Co wrote:
> On 21 mei, 08:47, Co <vonclausow...@gmail.com> wrote:
>> On 21 mei, 05:13, Jeff North <jnort...@yahoo.com.au> wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> On Fri, 20 May 2011 22:35:03 -0400, in comp.lang.php Jerry Stuckle
>>> <jstuck...@attglobal.net>
>>
>>> <ir78cp$53...@dont-email.me> wrote:
>>>> | 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
>>>> | > <vonclausow...@gmail.com>
>>>> | > <2407eb47-b406-432c-9aed-b76abc94a...@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:
>>
>>> [snip]
>>
>>>> | >> |<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.
>>
>>> Therefore the variables aren't initialised and would cause php errors
>>> - right?
>>
>>>> | > 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.
>>
>>> Methinks you are making too many assumptions - have you seen the full
>>> source code of the page?
>>
>>>> | > 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.
>>
>>> Who said anything about "add a row every time the page is displayed".
>>> According to your criteria there would never be any edit pages - only
>>> add pages.
>>
>>> If editing an existing item wouldn't you want to read the already
>>> stored data from the database?
>>
>>> i.e.
>>> // initialise variables to meaningful values
>>> // if editing an existing entry
>>> // read record
>>> // overwrite initialised variables
>>> // display the page
>>
>>>> | >> | The table is updated like this:
>>
>>> [snip]
>>
>>>> | >> | $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.
>>
>>> ...and how do you know this, hmmmm?
>>
>>>> | >> | $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.
>>
>>> The SQL statement should be ok - it's the "When I change of them the
>>> other one gets set back to default: 00-00-0000" I'm considering.
>>
>>>> | BTW - your sig separator is broken. It needs to be exactly
>>>> | hyphen-hyphen-space-newline.
>>
>>> Oh Jerry is now the sig line cop :-P
>>> Complain to the writers of Thunderbird as I couldn't care less about
>>> whether or not my sig appears 'correctly' in your news reader.
>>> -- -------------------------------------------------
>>> The supplied code is for guideline purposes only.
>>
>> Did some testing with the print command.
>> When I update the dates these are the results.
>>
>> when I change departure:
>> arrival 2009-0120 departure 11-07-01
>>
>> when I change arrival:
>> arrival 2009-07-01 departure 2011-01
>>
>> it doesn't make any sense to me.
>>
>> Marco
>
> After some more testing I figured out that the month value of the date
> which is not
> updated makes the date go corrupt (set to default). So someone the
> month value doesn't get read
> well from the $_POST['departure_month'].
>
> Any thoughts.
>
> MArco

I Think you need quotes around the dates

09:52:40 root@test[8]mysql> desc testDate;
+---------+------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+------+------+-----+---------+-------+
| SepDate | date | YES | | NULL | |
+---------+------+------+-----+---------+-------+
1 row in set (0.00 sec)

09:52:44 root@test[9]mysql> select * from testDate;
Empty set (0.00 sec)

09:52:51 root@test[10]mysql> insert into testDate values (2011-05-21);
Query OK, 1 row affected, 1 warning (0.00 sec)

09:53:09 root@test[11]mysql> select * from testDate;
+------------+
| SepDate |
+------------+
| 0000-00-00 |
+------------+
1 row in set (0.00 sec)

09:53:10 root@test[12]mysql> insert into testDate values ('2011-05-21');
Query OK, 1 row affected (0.00 sec)

09:53:27 root@test[13]mysql> select * from testDate;
+------------+
| SepDate |
+------------+
| 0000-00-00 |
| 2011-05-21 |
+------------+
2 rows in set (0.00 sec)


--
Luuk
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: is dis da place?
Next Topic: foreach in reverse
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 20:36:48 GMT 2024

Total time taken to generate the page: 0.04109 seconds