Reply to Re: Storing player numbers

Your name:

Reply:


Posted by Hilarion on 10/08/00 11:25

MattMika <mattmika@hotmail.com> wrote:
> I need to store player numbers in a DB with a range from 0-99, ie. 00,
> 07, 99, etc.. These will be entered by way of form. Whats the best way
> to do this?
>
> I've messed with char(2) and validating but,
>
> if (ereg("[^0-9]{2}", $_POST['pnum'])) {

This regular expression allows anything that has two chars which are
NOT digits somewhere inside, so "aa", "aaaa", "1aa2" etc. will be
accepted. It should be something like this:

if (ereg('^[0-9]{2}$', $_POST['pnum']))

> or
> if (is_numeric($_POST['pnum'])) {

This will allow numbers without leading zero, numbers which are not
integer, exponential values, negative values etc. Should not
accept text values (like 'aa').


> return true even if 'aa' is entered. I assume its seeing the chr(#).

In case of the regular expression you used it would act like that,
but in case of "is_numeric" it should not.


Do you really need the leading zero ("00" instead of "0", "01" instead
of "1")? If so, then use CHAR(2) in DB, and the regular expression
I gave above (or use <select> in your <form> to allow only selection
of valid values). You can (and should if it's possible) also use
CHECK constraint in your DB. Something like this (assuming the column
in the DB is called FLD):
(SUBSTR( FLD, 1, 1 ) BETWEEN '0' AND '9') AND
(SUBSTR( FLD, 2, 1 ) BETWEEN '0' AND '9')


Hilarion

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация