title: how to tell if a mysql insert is successful
body: <p>I'm learning MySQL transactions. I've searched for answers to this, but they all seem to use PHP to make what I want to do work. Here's the example of what I'm trying to do:</p>
  
  <ol>
  <li>Begin the transaction</li>
  <li>Update Table1</li>
  <li>Insert into Table2</li>
  <li>If Insert is successful, 
  a. then insert into Table3 and commit.
  b. else rollback the transaction.</li>
  </ol>
  
  <p>I don't understand how to determine programmatically whether the insert at step 3 was successful. Sure, I can query the table and see, but I thought there was some way to use the return value, but it seems that only works when I'm using PHP to do the transaction. </p>
  
  <p>This is the code block for what I'm trying - it doesn't work:</p>
  
  <pre><code>begin;
  start transaction;
  -- attempt to reduce inventory
  update store_inventory set item_qty = item_qty - 2 where id = 1; 
  update store_inventory set item_qty = item_qty -1 where id = 5;
  
  -- insert the order record and check whether it succeded
  insert into store_orders (purchaser_name, purchase_date) 
  values ('test user', now());
      -- if successful, do final insert and commit
  if Row_Count() &gt; 0 Then     
  insert into store_inventory (order_id, inventory_id, item_qty)
  values (1, 1, 2),
          (1, 2, 1);
  commit;
  else    -- otherwise rollback
  rollback;
  end if;
  
  end;
  </code></pre>