简体   繁体   中英

mySQL removing leading zeros even with data type set as string

I have a mySQL address database and for the zip code column I need mySQL to keep the leading zeros. No matter what I do, the leading zeros are removed from the zip codes. I tried setting the column as both varchar and char thinking the string type would fix the problem, but this is not working. I can manually change the numbers within the database to include the zero, but using PHP to add the zip results in "01234" being changed to "1234".

Any other suggestions? Thanks!

Code:

$input_zip = "01234";

$query_buildzip = "INSERT INTO dir_zipcode(zipcode) VALUES($input_zip)";

$result_buildzip = mysql_query($query_buildzip);

You're missing the quotes:

$query_buildzip = "INSERT INTO dir_zipcode(zipcode) VALUES('$input_zip')";
//                                                         ^          ^

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM