Input data from modal form into three different MySQL tables

I have a web Ajax web form that I’m trying to insert the data into three different MySQL database tables.

I have a database with three tables

Table 1: Orders
id - primary key
Name
Date
Invoice
ebay
Shipper

Table 2: Products
Product_id - primary key
Product
id- foreign Key

Table 3: SMA
sma_id - primary key
sma
id - foreign key

I have all these tables in a web form using a modal and using Ajax.

Need the insert code to be able to insert the data from the web form to the MySQL tables with the ID primary key passed to the foreign keys.

Would love if someone can help me with that code

Thanks

First insert the new Order. Then use mysqli_insert_id (Or PDO::lastInsertId) to retrieve the new order id:

$newOrderId = mysqli_insert_id($link);

And then insert the records to the other tables setting the foreign id’s with $newOrderId.

Hi Frankbeen,

Yes but I am not sure how to write the statement for the two tables, I put them straight after each other but did not work.

How would I put the three in one code.

Sorry I am very new to coding

Thanks

As long as you do not show any code, people are barely able to help you. And “did not work” statements are not useful, nobody - except yourself - sits in front of your monitor and nobody can watch into your head. You have to be sure to provide all neccessary information that people can reproduce your problem, just look at what you are writing and think about if anybody can rely on that.

2 Likes

As Chorn said show us some code.

Sponsor our Newsletter | Privacy Policy | Terms of Service