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!
$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) {
echo "<font class="css-error">*Phone numbers have a 14 character max and a 7 character minimum.</font><br>";
} else {
$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;
}
}
}
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?
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.
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...
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!)