0

I am trying to insert queries into multiple tables using the following code. I have tried without the TRANSACTION and it will not work, individually they work. Any help would be much appreciated.
Thanks in advance.

$query = mysql_query("BEGIN;  
INSERT INTO `uc` (`ANO`, `CNO`, `P`) VALUES ('$ano', '$cno', '$p');  
INSERT INTO `ct` (`ANO`, `CNO`, `RNO`) VALUES ('$ano','$cno','$rno');  
COMMIT;");   

$query_run = mysql_query($query);
3
  • Ah, multiple tables - stackoverflow.com/questions/10471757/… Commented Mar 13, 2013 at 2:24
  • You should upgrade to PDO Commented Mar 13, 2013 at 2:30
  • if you were using mysqli you could use mysqli_multi_query Commented Mar 13, 2013 at 3:13

1 Answer 1

0
$query = "BEGIN";
mysql_query($query) or die (mysql_error());

$query = "INSERT INTO `uc` (`ANO`, `CNO`, `P`) VALUES ('$ano', '$cno', '$p')";
mysql_query($query) or die (mysql_error());

$query = "INSERT INTO `ct` (`ANO`, `CNO`, `RNO`) VALUES ('$ano','$cno','$rno')";
mysql_query($query) or die (mysql_error());

$query = "COMMIT";
mysql_query($query) or die (mysql_error());
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.