title: CodeIgniter - Multiple table insert using transactions
body: <p>Im currently following a tutorial on creating a forum in PHP / MySQL ... and im trying to implement it into my CodeIgniter project.</p>
  
  <p>I have hit a snag that i have never dealt with before, transactions ... I have read the documentation on codeigniters transactions, but im not really understanding it considering the code i need to convert.</p>
  
  <p>I was wondering if someone could take the code below and turn it into codeigniters transaction code for me, i have tried doing it myself but its using multiple tables and i just get completely confused.</p>
  
  <p>Any help would be great, code is below:</p>
  
  <pre><code>$query = "BEGIN WORK;";
  $result = mysql_query($query)
  
  if(!$result) {
      echo 'An error has occured';
  } else {
      $sql = "INSERT INTO topics(t_subeject,date,cat) VALUES ($_POST['subject'],NOW(),$_POST['cat'])";
      $result = mysql_query($sql);
  
      if(!$result) {
          echo 'An error has occured';
          $sql = "ROLLBACK;";
          $result = mysql_query($query)
      } else {
          $topid = mysql_insery_id();
          $sql = "INSERT INTO posts(content, date) VALUES ($_POST['content'],NOW())";
          $result = mysql_query($sql);
  
          if(!$result) {
              echo 'An error has occured';
              $sql = "ROLLBACK;";
              $result = mysql_query($sql);
          } else {
              $sql = "COMMIT;";
              $result = mysql_query($sql);
              echo 'Insert successful!';
          }
      }
  }
  </code></pre>