如何插入多对多Tabel自动递增

时间:2016-06-28 19:54:43

标签: php mysql

A                 B                 C
-------         ---------         ------------
id_A*           id_B*              id_C*
name            id_A**             name
address         id_C**

我在上面的示例中创建了一个表我尝试在表A中执行输入,然后在C中执行输入,但是如果我想输入C然后将输入表B与表A一起输入怎么办? ,自动增量主键中的所有表

            <input type="text" name="id_A" />
        <input type="text" name="id_B" />
        <input type="text" name="name" />
        <input type="text" name="address" />
        <select class="form-control" name="id_C">
                <?php
                    $query  = "select * from C";
                    $r      = mysql_query($query);
                    while ($row=mysql_fetch_array($r)) {

                ?>
            <option value="<?php echo $row['id_C'];?>" name="id_C"><?php echo $row['name'];?></option>
                <?php
                    }
                ?>
        </select>

然后

            isset($_POST['submit'])) {
        $id_A               = $_POST['id_A'];
        $name               = $_POST['name'];
        $address            = $_POST['address'];

        $q      = "insert into A (id_A,name,address) VALUES('$id_A','$name','$address')";
        $dq     = mysql_query($q);
        $id_B   = $_POST['id_B'];

            $query = mysql_query("insert into B(id_b,id_A,id_C) values('$id_b', '$id_A' ,'$id_C')");

请帮帮我, I&#39;我是一个真正的混淆

0 个答案:

没有答案