I have one field on my submission form which is for the User's zip code. Originally I had it set to int(5), but when I submit my form with a five digit zip code it only stores 4 of the characters, omitting the first digit.

Example: On the form I type in for zip code: 07084. I then submit it and check the database but what is saved is 7084.

When I submit 07085 it is saved as 7085.

I tried changing it fron an int to a varchar but had the same results.

Hi, if you're using a prepared statement to insert the data, then submit the zipcode as a string, not as integer, this should solve the issue for you. The table column must be char or varchar, as you're already doing.

I wouldnt recommend saving the zip code as an interger either. The information in a zip code isnt going to be used in any type of arithmetic. The zip just happens to be using numbers as its characters. I'd store the zip in char (if you are absolutely sure of the length) or varchar (if you are collecting zip codes from different regions that may have different lengths) as well. I dont think that the benefit of storing it as an integer (space and handling) justifies the use of integer here.

With regards to displaying the 5 digits, you can pad it with leading zeros either by your SQL statement or in php.

For example, if you are using MySQL, your SQL statement could look like...

SELECT LPAD(zip, 5, '0') as zipcode FROM table;

Thank you both. I will try your solutions.

That worked perfectly. Thank you!