Inserting data into multiple tables in PHP

Source: Internet
Author: User
Inserting data into multiple tables in PHP
Table: order_table
Fields: order_id, (table:) rem_table.rem_id (primary key), Order_number
Table: deal_table
Fields: deal_id, order_id, Deal_date, Deal_information, Deal_man

Insert data into these two tables: Order_number, Deal_date, Deal_information, Deal_man

What should I do? where the data is inserted, the field rem_table.rem_id cannot be empty, because in the future to query the data, to be used, (rem_table and order_table query)

------Solution--------------------
First use if to determine, and then insert.

If ()

insert into ();
Mysql->query ();
Inser into ();
Mysql->query ();

Else
{
}
------Solution--------------------
The order table is the "father" of the deal table (according to the design of your table)
So it's all first. (insert) Order and then (insert) deal
Options available for both options
1. Insert Order② query Order_id③ insert deal with database self-increment ①
2.ID Insert Order (write the generated ID directly) ② insert deal with PHP build ①

In Method 2, note that the ID must have some complexity, as we create the image name can not be repeated
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.