Jump to content


Photo

not storing mobile numbers properly...


  • Please log in to reply
5 replies to this topic

#1 mandrill

mandrill
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 29 September 2006 - 02:31 PM

I'm trying to store mobile phone numbers in a database as the VARCHAR data type but they keep getting stored as 2147483647. There's no problems with landline numbers (which start with 01 in my country) but mobile numbers (07etc.) seem to be problematic. Is there anyway I can force MySQL to store it as a string rather than an integer? I've tried changing the data type (All the INTs unsigned with zerofill, VARCHAR, CHAR, all the TEXTS, and the various BLOBs) and it always stores them as 2147483647. Any advice would be most appreciated as I've been tearing my hair out over this for the last two days.
---------------------------------------------------
I can't affor to pwn,
do you think I could r3nt?
http://keithneilson.co.uk
---------------------------------------------------

#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 29 September 2006 - 05:13 PM

You should have no issue at all with leading zeros on a VARCHAR column.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#3 mandrill

mandrill
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 29 September 2006 - 07:05 PM

Exactly. Which is what is so baffling.
---------------------------------------------------
I can't affor to pwn,
do you think I could r3nt?
http://keithneilson.co.uk
---------------------------------------------------

#4 printf

printf
  • Staff Alumni
  • Advanced Member
  • 889 posts

Posted 29 September 2006 - 09:30 PM

Are you sure it going into the database, I mean it not your scripting doing it!

me!

#5 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 29 September 2006 - 10:43 PM

Good point... if it's being stored a weakly typed variable, and not explicitly as a string, you could just get the numerical equivalent.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.

#6 mandrill

mandrill
  • Members
  • Pip
  • Newbie
  • 7 posts

Posted 30 September 2006 - 07:07 PM

I went through the code with a fine toothed comb and found this:
$insertSQL = sprintf("INSERT INTO customers (CustomerNumber, Title, Address, Surname, WorkNumber, HomeNumber, MobileNumber, Notes) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($custID, "text"),
					   GetSQLValueString($_POST['title'], "text"),
                       GetSQLValueString($_POST['address'], "text"),
                       GetSQLValueString($_POST['surname'], "text"),
                       GetSQLValueString($_POST['worknumber'], "int"),
                       GetSQLValueString($_POST['homenumber'], "int"),
                       GetSQLValueString($_POST['mobilenumber'], "int"),
                       GetSQLValueString($_POST['notes'], "text"));
I feel like an idiot. I changed the int's to text's and now it works fine. Thanks anyway :)
---------------------------------------------------
I can't affor to pwn,
do you think I could r3nt?
http://keithneilson.co.uk
---------------------------------------------------




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users