如何在没有id的情况下插入数据。其中id是表

时间:2018-04-06 02:18:53

标签: php mysql sql for-loop

我正在尝试将数据作为数组插入表中。表id中的地方是主键和自动增量。但是当我插入数据时,id不会增加表,并且其余字段不会插入。我需要在示例数据下插入

data::
Array
(
    [0] => Array
        (
            [nric] => anonymous
            [id] => 13
            [fullname] => anonymous
            [gender] => m
            [password] => anonymous
            [address] => 
            [postcode] => 
            [state] => 
            [contact1] => 
            [email] => nomail
            [expirydate] => 
        )

    [1] => Array
        (
            [nric] => dhoni1234
            [id] => 323
            [fullname] => dhoni
            [gender] => m
            [password] => dhoni1234
            [address] => ntg
            [postcode] => 
            [state] => 
            [contact1] => 
            [email] => dhoni@gmail.com
            [expirydate] => 
        )

    [2] => Array
        (
            [nric] => dhoni123
            [id] => 324
            [fullname] => dhoni
            [gender] => m
            [password] => dhoni123
            [address] => ntg
            [postcode] => 
            [state] => 
            [contact1] => 
            [email] => dhoni@gmail.com
            [expirydate] => 
        )

及以下是我的代码插入到object_data表中,其中表id是autoincrement。当我写下面的查询时,它只是插入数组[0]数据。不插入重映射数据

$jfile = file_get_contents('php://input');
$final_res = json_decode($jfile, true) ;
$data =  $final_res['users'];

for($x=0; $x<count($data); $x++){

  $sql ="INSERT INTO `object_data` ( `description`, `type`, `owner`) VALUES ('".$data[$x]['email']."','usr','6')

   ";
      $update2 = mysqli_query($db,$sql);
}

id是table.column描述中的autou增量(value:email)有更多数据,但只有一个值是惰性的。请帮我解析this.id是table.column描述中的autou增量(value:email)更多的数据,但只有一个值是惰性的。请帮助我理清这个

0 个答案:

没有答案