Really weird!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Really weird!

Post 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?
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

What type of feild is `phone_num`?
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post by php_wiz_kid »

It's an input box being put in a integer column in a database.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

...

Post 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).
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post by php_wiz_kid »

The integer is set to hold 14 numbers in the database.
User avatar
PaTTeR
Forum Commoner
Posts: 56
Joined: Wed Jul 10, 2002 7:39 am
Location: Bulgaria
Contact:

Post 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.
php_wiz_kid
Forum Contributor
Posts: 181
Joined: Tue Jun 24, 2003 7:33 pm

Post 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?
kcomer
Forum Contributor
Posts: 108
Joined: Tue Aug 27, 2002 8:50 am

Post 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
qartis
Forum Contributor
Posts: 271
Joined: Sat Dec 14, 2002 4:43 pm
Location: BC, Canada
Contact:

Post by qartis »

Especially if you aren't stripping out the hyphens, spaces, periods et. al
fractalvibes
Forum Contributor
Posts: 335
Joined: Thu Sep 26, 2002 6:14 pm
Location: Waco, Texas

Post 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.
Post Reply