Get a complete number from GET method, '0' is missing [SLVD]

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
raulbolanos
Forum Newbie
Posts: 14
Joined: Fri May 07, 2010 3:14 pm

Get a complete number from GET method, '0' is missing [SLVD]

Post by raulbolanos »

Hi guys,

I have the next issue.

I want to get a telephone number from GET method:

Code: Select all

$tel = $_GET['tel'];
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.
Last edited by raulbolanos on Thu May 13, 2010 11:15 am, edited 1 time in total.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Get a complete number from GET method, '0' is missing

Post by AbraCadaver »

Dunno, works for me. Do you echo $tel?
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Re: Get a complete number from GET method, '0' is missing

Post 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.
raulbolanos
Forum Newbie
Posts: 14
Joined: Fri May 07, 2010 3:14 pm

Re: Get a complete number from GET method, '0' is missing

Post 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.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Get a complete number from GET method, '0' is missing

Post 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".
User avatar
hypedupdawg
Forum Commoner
Posts: 74
Joined: Sat Apr 10, 2010 5:21 am

Re: Get a complete number from GET method, '0' is missing

Post 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().
raulbolanos
Forum Newbie
Posts: 14
Joined: Fri May 07, 2010 3:14 pm

Re: Get a complete number from GET method, '0' is missing

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