Page 1 of 1

Really weird!

Posted: Mon Jul 21, 2003 11:26 pm
by php_wiz_kid
This piece of code

Code: Select all

$new_phone_num = $_POSTї'phone_num']; 
if($submit) {
					if(!empty($new_phone_num)) {
						if(strlen($new_phone_num) > 14 or strlen($new_phone_num) < 7) &#123;
							echo "<font class="css-error">*Phone numbers have a 14 character max and a 7 character minimum.</font><br>";
						&#125; else &#123;
							$mysql_query = "UPDATE rp_users SET phone_num = '$new_phone_num' WHERE userid = '$userid'";
							$mysql_query_result = mysql_query($mysql_query);
							
							$phone_num = $new_phone_num;
						&#125;
					&#125;
				&#125;
is run to put a phone number into a database. The total number of characters they can have is 14, and the minimum is 7. Now when they put up to 9 characters it records into the database just fine. When they put that 10th character in the number that gets updated into the database isn't the number submitted.

So if I put 555 5555 (minus the space) that number gets recorded into the database, but if I put 555 555 5555 this number somehow is put in the database 2147483647 (actual number generated). Anybody know why this is?

Posted: Tue Jul 22, 2003 2:05 am
by qartis
What type of feild is `phone_num`?

Posted: Tue Jul 22, 2003 12:57 pm
by php_wiz_kid
It's an input box being put in a integer column in a database.

...

Posted: Tue Jul 22, 2003 1:26 pm
by kettle_drum
I think qartis is refering to the field type in the mysql database. If the field is too small to hold a 10 digit number then it wont be able to do it.

If this is the case try changing the field in the database to VARCHAR(14).

Posted: Tue Jul 22, 2003 1:30 pm
by php_wiz_kid
The integer is set to hold 14 numbers in the database.

Posted: Tue Jul 22, 2003 1:59 pm
by PaTTeR
INT type in MySQL can't hold values bigger than 2147483647 , if you declare it as UNSIGNED max value is 4294967295. So if you need to keep big values change column type.

Posted: Tue Jul 22, 2003 2:57 pm
by php_wiz_kid
ohhhhhh, ok, thanks a lot. Is there an interger type similar to TINYINT except it's for bigger numbers, like BIGINT or something?

Posted: Tue Jul 22, 2003 7:30 pm
by kcomer
Better question is, why are you storing a phone number as an int? Will you be doing calculations on it? (adding phone numbers?). I usually go with varchar for phone numbers, ss#'s, etc...

Keith

Posted: Tue Jul 22, 2003 7:33 pm
by qartis
Especially if you aren't stripping out the hyphens, spaces, periods et. al

Posted: Tue Jul 22, 2003 10:42 pm
by fractalvibes
Yes, unless you are going to do calculations on the phone number, char or varchar would be appropriate, esp. given the number of variations/conventions:
123 456 7890
123-456-7890
(123) 456-7890
123.456.7890
(123)456-7890 Ext. 989
Plus any extensions for foreign exchanges.

If you have a need to capture phone numbers to examine by particular
Area Code, exchange, etc. you may want to capture as separate strings
and store separately. (and edit for numeric!)

Phil J.