How to insert fields to different tables at once? 5 Main Tables: TEMP, PAYMENT, CUSTOMER, PURCHASE, and PRODUCT.


TEMP:     TempID, Email, Name, Product1, Product2, Date, Amount
PAYMENT:  PaymentID, Status, Amount, Date
CUSTOMER: CustomerID, Email, Name
PURCHASE: CustomerID, PaymentID, ProductID, Quantity
PRODUCT:  ProductID, ProductName, Price


How to insert each field from TEMP where TEMP.Email = '$Email' to PAYMENT, CUSTOMER, PURCHASE, and PRODUCT:


TEMP.Email    >> CUSTOMER.Email
TEMP.Name     >> CUSTOMER.Name
TEMP.Product1 >> PURCHASE.ProductID
TEMP.Product2 >> PURCHASE.ProductID
TEMP.Date     >> PAYMENT.Date
TEMP.Amount   >> PAYMENT.Amount
You could write an (AFTER?) INSERT trigger, like this:

CREATE TRIGGER temp_inserts_trg AFTER INSERT ON temp
    FOR EACH ROW BEGIN
        INSERT INTO customer VALUES(NEW.ID, NEW.Email, NEW.Name);
        INSERT INTO payment...
        ...
    END;


Check the MySQL CREATE TRIGGER documentation for more info.