Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Sprawdzanie int, jako string...
Largo
post
Post #1





Grupa: Zarejestrowani
Postów: 203
Pomógł: 6
Dołączył: 11.09.2005

Ostrzeżenie: (0%)
-----


Witam,

Mam chyba dość nie typowy problem. Zacznę od zaprezentowania kodu:

  1. <?php
  2. //-------------------------------------
  3.        // Check all possible errors...
  4.        //-------------------------------------
  5.        if ( !$this->to_user['id'] )
  6.        {
  7.            $this->ipsclass->error(array(LEVEL => 1, MSG => 'id_not_exists'));
  8.        }
  9.        else if ( $this->ipsclass->input['to_id'] == $this->ipsclass->member['id'] )
  10.        {
  11.            $this->ipsclass->error(array(LEVEL => 1, MSG => 'send_to_you'));
  12.        }
  13.        else if ( $this->ipsclass->member['mgroup'] == $this->ipsclass->vars['banned_group'] )
  14.        {
  15.            $this->ipsclass->error(array(LEVEL => 1, MSG => 'send_to_banned'));
  16.        }
  17.        else if ( $this->ipsclass->input['amount'] <= 0 )
  18.        {
  19.            $this->ipsclass->error(array(LEVEL => 1, MSG => 'enough_fg'));
  20.        }
  21.        else if ( $this->ipsclass->input['amount'] > $this->ipsclass->member['fg'] )
  22.        {
  23.            $this->ipsclass->error(array(LEVEL => 1, MSG => 'more_than_have'));
  24.        }
  25.        else if ( $this->ipsclass->input['from'] != $this->ipsclass->member['id'] )
  26.        {
  27.            $this->ipsclass->error(array(LEVEL => 1, MSG => 'problem_id'));
  28.        }
  29.        else if ( $this->ipsclass->member['fg_locked'] == 1 )
  30.        {
  31.            $this->ipsclass->error(array(LEVEL => 1, MSG => 'fg_locked'));
  32.        }
  33.        else if ( $this->ipsclass->member['fg_password'] != md5($this->ipsclass->input['fg_password']) )
  34.        {
  35.            $this->ipsclass->error(array(LEVEL => 1, MSG => 'pass_not_match'));
  36.        }
  37. ?>


Warunek nad którym ubolewam to:

  1. <?php
  2. else if ( $this->ipsclass->input['amount'] > $this->ipsclass->member['fg'] )
  3.        {
  4.            $this->ipsclass->error(array(LEVEL => 1, MSG => 'more_than_have'));
  5.        }
  6. ?>


Wartości? A więc tutaj jest prosta odpowiedź - z bazy ( $this->ipsclass->member['fg'] ) pobiera w formie x, xxx.xx ( number_format($data, 2, '.', ',' ), a pole usera ( $this->ipsclass->input['amount'] ) jest pobierane z formularza również jako string. Gdzie jest problem? Ułamki, tu się sypie. Kolejna sprawa to setki, tysięcy nawet nie sprawdzałem. Jak takie coś sprawdzać?

PS. Narzucanie typów nic nie daję.

Pozdrawiam,
Largo
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Largo
post
Post #2





Grupa: Zarejestrowani
Postów: 203
Pomógł: 6
Dołączył: 11.09.2005

Ostrzeżenie: (0%)
-----


Witam,

Zwykła notacja x xxx.xx nic nie dała. Nie rozumiem tego w ogóle... intval() nie przejdzie, ponieważ muszą być ułamki.

PS. Szkoda, że PHP nie ma rzutowania danych typów dla zmiennych...

@down
Tak.

Pozdrawiam,
Largo

Ten post edytował Largo 22.01.2009, 23:05:08
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 9.10.2025 - 05:22