bot
bot

Reputation: 3

How to update two tables with MySQL and PHP?

I was wondering how do I update two tables using mysql and php?

How would I add the second table to the code?

Here is the code below.

$dbc = mysqli_query($mysqli,"UPDATE tags SET count='$tag_info_count' WHERE id='$tag_info_id'")

Upvotes: 0

Views: 542

Answers (2)

carillonator
carillonator

Reputation: 4743

check out Execute Multiple MySQL Queries from One String in PHP.

Otherwise, write separate query statements in your PHP.

Upvotes: 0

Byron Whitlock
Byron Whitlock

Reputation: 53861

You create a transaction. I forget the transaction syntax for mysqli, but basically

try 
{
   mysql_begin_transaction(); //not correct syntax
   mysql_query("UPDATE table1..."); // not correct syntax
   mysql_query("UPDATE table2..."); // not correct syntax
   msyql_commit_transaction() // not correct syntax
}
catch (Exception E)
{
   msyql_rollback_transaction(); // not correct syntax
}

Upvotes: 1

Related Questions