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 Link to comment https://forums.phpfreaks.com/topic/209953-cannot-insert-integers-that-begin-with-0-zero-using-mysql-insert/ 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. Link to comment https://forums.phpfreaks.com/topic/209953-cannot-insert-integers-that-begin-with-0-zero-using-mysql-insert/#findComment-1095838 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 Link to comment https://forums.phpfreaks.com/topic/209953-cannot-insert-integers-that-begin-with-0-zero-using-mysql-insert/#findComment-1095868 Share on other sites More sharing options...
slyte33 Posted August 6, 2010 Author Share Posted August 6, 2010 Thanks it works fine! Link to comment https://forums.phpfreaks.com/topic/209953-cannot-insert-integers-that-begin-with-0-zero-using-mysql-insert/#findComment-1095871 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.