can I know why it is not inserting zero to my database when its type in integer. I have a table called contact and there is a column to keep users’ 10 digits length mobile no. This number generally start with 0. Eg. 0713423454, 0234324545 etc.
In my table I have create that column like this..
mobile INT(10) NOT NULL,
In php I validate it something like this…
// Check for a mobile number:
if ( !empty($_POST['mobile'])) {
$number = $_POST['mobile'];
if (preg_match('/(0[0-9]{9})/', $number)) {
$mobile = mysqli_real_escape_string ( $dbc, $number);
} else {
$reg_errors['mobile'] = 'You are NOT entered valid Mobile number!';
}
} else {
$reg_errors['mobile'] = 'Mobile number can not be empty!';
}
But when inserting mobile number to database its going without 0 like this 234223434, 435453545 etc.
So I would like to know is there a way to insert my mobile number with 0 to database..
Thank you.
Integers do not (cannot) have leading zeros. That is, both ‘099’ and ’99’ represent the same numeric value1.
Use a char or varchar instead.
1 Sometimes a leading zero in the text-representation of a number specifies the [octal] base, but that is not the case here.