Skip to content
Advertisement

Insert DATA into 2 tables using one Query using PHP and Mysql

I have 2 tables that I am trying to insert data into using PHP

JavaScript

wine_id is auto incremented, then This is my other table

JavaScript

For the STOCK table I have stock ID as Auto incremented and wine_id is foreign-key so All i need to insert is quantity.

I have a syntax like this:

JavaScript

If there is another way to do so please suggest and I would like some examples please.

Advertisement

Answer

You need to separate your two INSERT statements with a semicolon.

This(mysql_*) extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. Switching to PreparedStatements is even more better to ward off SQL Injection attacks !

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement