Page 1 of 1
Get a complete number from GET method, '0' is missing [SLVD]
Posted: Fri May 07, 2010 3:18 pm
by raulbolanos
Hi guys,
I have the next issue.
I want to get a telephone number from GET method:
The problem is, that I send any number starting with '0' and php ingnores it, for example '0123456789'. What php saves is '123456789'.
What can I do to keep this number?
thank you in advance.
Re: Get a complete number from GET method, '0' is missing
Posted: Fri May 07, 2010 3:28 pm
by AbraCadaver
Dunno, works for me. Do you echo $tel?
Re: Get a complete number from GET method, '0' is missing
Posted: Fri May 07, 2010 3:34 pm
by John Cartwright
I assume your talking about mysql saves it without the leading 0. If you want to preserve the leading 0, change the your numerical column type to use zerofill.
Re: Get a complete number from GET method, '0' is missing
Posted: Mon May 10, 2010 11:55 am
by raulbolanos
John Cartwright wrote:I assume your talking about mysql saves it without the leading 0. If you want to preserve the leading 0, change the your numerical column type to use zerofill.
John, thank you for the answer. It seems correct but it is not exactly what I need. First of all, it is a Varchar type column for numbers, which saves numbers like this:
045-348-102-6874
or
01(45)3481026874
It may differ a lot, therefore I need the column like string to be able to save numbers with parenthesis, high script and so on.
Re: Get a complete number from GET method, '0' is missing
Posted: Mon May 10, 2010 1:13 pm
by califdon
Just make sure that at every point that you handle the data (PHP, Javascript, MySQL, etc.), you are handling it as a STRING, not a number! That means always enclosing the value in quotation marks. Somewhere along the line, your script is handling it as a numeric value, that's why the leading zero is being dropped. As a string, "0" is just another ASCII character and, believe me, none of these languages will drop an ASCII "0".
Re: Get a complete number from GET method, '0' is missing
Posted: Mon May 10, 2010 4:27 pm
by hypedupdawg
Yes, as it is a telephone number, you are not likely to want to use it for Maths functions, which is the whole point of using numbers. If you want to turn a number into a string you can use the function strval().
Re: Get a complete number from GET method, '0' is missing
Posted: Wed May 12, 2010 3:27 pm
by raulbolanos
califdon wrote:Just make sure that at every point that you handle the data (PHP, Javascript, MySQL, etc.), you are handling it as a STRING, not a number! That means always enclosing the value in quotation marks. Somewhere along the line, your script is handling it as a numeric value, that's why the leading zero is being dropped. As a string, "0" is just another ASCII character and, believe me, none of these languages will drop an ASCII "0".
You are right.. the Quotes at the PHP code were missing... now it's working perfectly.
Thank you guys.
Peace and Love!!