MySQL removes the first digit

I enter the data into mySQL database through a PHP script, but for some reason, when I check the database, all phone numbers have their first digit, so 0123456789 is displayed as 123456789 in the database, but if I change the data type from INT before TEXT, it will display correctly, I doubt very much that it will remain TEXT, although, as I am sure, this will lead to complications in the future, as the database application starts to become more complicated, here is the PHP code.

    <?php


$gender = $_POST['gender']; 

$first_name = $_POST['first_name']; 

$second_name = $_POST['second_name']; 

$id_number = $_POST['id_number']; 

$home_number = $_POST['home_number']; 

$cell_work = $_POST['cell_work']; 

$email_address = $_POST['email_address']; 


        $curDate = date("Y-m-d");

        mysql_connect ("server", "user", "pass") or die ('Error: ' . mysql_error());
        mysql_select_db ("database");

        $query = "INSERT INTO table (id,gender,first_name,second_name,id_number,home_number,cell_work,email_address,date) VALUES('NULL','".$gender."','".$first_name."','".$second_name."','".$id_number."','".$home_number."','".$cell_work."','".$email_address."','".$curDate."' )";

        mysql_query($query) or die (mysql_error());

        ?>

Thanx in advance!

+3
source share
3 answers

CHAR, VARCHAR TEXT. CHAR VARCHAR , TEXT . CHAR, VARCHAR .

, INT, , 0123456789 123456789 ( , 0 : P). , . .

+2

, 0000001 1...

, , Google.

0

, ZEROFILL:

ALTER TABLE `sweet_table` CHANGE `id` `id` INT( 9 ) UNSIGNED ZEROFILL NOT NULL

.

0

Source: https://habr.com/ru/post/1740758/


All Articles