View Full Version : inputting numbers into MySQL
December 27, 2003, 03:07 PM
ok.. i feel kinda dumb posting this.. but I need this to work and it hasn't thus far...
i need to capture telephone numbers in a MySQL database...
now if the user enters 8769312323 all is well
but as soon as a none numeric character is entered I get truncation - 876-9312323 = 876... (876) = null
need some help here.. should this be some addslashes and strip slashes thing.. cause I've pretty much exhausted the options from MySQL...
>>> grumble grumble << I can design and implement huge applcations.. but number capture eludes me <<<
December 27, 2003, 08:24 PM
It's important to note that a phone number should not be treated as a 'number' in it's conventional sense. Values need only be stored as numbers if you plan to do some calculation on them or use them as increment-able keys.
More specifically, a 'phone number' isn't a numeric value at all. It's actually a STRING made up of numerical characters. As you can appreciate, it's impossible to add or subtract a value to or from a phone number, because it's not a number at all.
To solve your problem, change the telephone data type to varchar(16) (which would allow a number with the following format: (876) 555 - 5555, and you really shouldn't be storing numbers with more characters than that) or something similar.
And remember a simple rule of thumb, if you're not calculating, don't make it a number, no matter how 'appropriate' it seems.
December 27, 2003, 09:08 PM
That's my prob...
I had it set to varchar(16)...then (32).. it STILL truncated. I've tested it myself as well as had other test... it always truncates at the non-numeric character. ::) ::)
December 27, 2003, 09:29 PM
OK. Well in that case I'm guessing your problem is that you're not putting single quotes around the telephone variable.
Your statement should look something like this:
mysql_query("insert into some_table values ('$var1', '$var2','$telephone', '$var4'");
Note that I'm using single quotes, not double.
Lemme know if that works.
December 28, 2003, 07:11 AM
found the prob...
was using D-Weaver to script and it inserted an "int" descriptor in the insert code so though the database was set up it was only being passed INT data.. changed it and all is well.
guess this is a one-up for hand-coding ;D ::) ;D
Powered by vBulletin® Version 4.2.0 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.