Jump to content

Cannot insert integers that begin with "0" (zero) using mysql insert


slyte33

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.