I have 2 tables that I am trying to insert data into using PHP
Table: WINE ----------------------------------------------------------------- | wine_id | wine_type | country | indicator | color | -----------------------------------------------------------------
wine_id is auto incremented, then This is my other table
Table: stock -------------------------------------- | stock_id | wine_id | quantity | --------------------------------------
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:
$sql = mysql_query("INSERT INTO TABLE1(field1, field2, field3) VALUES('value1',value2,value3) INSERT INTO STOCK(field) VALUES ('value1')");
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 !