slyte33 Posted August 6, 2010 Share Posted August 6, 2010 Hello, I'm having a bit of a problem here, all help to this issues would be much appreciated I am trying to use text boxes to insert numbers into the database based on what is inputed. If I have a string, like this for example: $variable = 09385493; And I want to insert it into the database like this: mysql_query("INSERT INTO integers(number) VALUES ('$variable')"); When checking the integers table in my database, looking at the number field, the $variable that was inserted is outputted as 9385493 Notice the number zero was taken out of the front of the number. If the number is double 0's (009385493), both of those zero's would disappear, too. Thanks Quote Link to comment Share on other sites More sharing options...
dolrichfortich Posted August 6, 2010 Share Posted August 6, 2010 You should convert the number field to varchar if you want to retain those zeros. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted August 6, 2010 Share Posted August 6, 2010 Don't worry how the number is stored. If you want to display it with leading zeros you can do that with the printf function: <?php $var = 9385493; printf("%08d",$var); // <<---- outputs 09385493 printf("%09d",$var); // <<---- outputs 009385493 ?> Ken Quote Link to comment Share on other sites More sharing options...
slyte33 Posted August 6, 2010 Author Share Posted August 6, 2010 Thanks it works fine! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.