title: insert and update in different table in one form
body: <p>Its possible insert data in table A but in the same time, update data in table B in one submit button?where should i put the insert query? Should i put them in the update query or declare one more query? I am a beginner in writing code. Please someone help me solving this problem. Below is my page code.</p>
  
  <pre><code>&lt;?php
  include ("supsrwk_epenyenggaraan.php");
   ?&gt;
  &lt;?php
  
  // initialize the session
  
  if (!isset($_SESSION)) {
      session_start();
  }
  
  // ** Logout the current user. **
  
  $logoutAction = $_SERVER['PHP_SELF'] . "?doLogout=true";
  
  if ((isset($_SERVER['QUERY_STRING'])) &amp;&amp; ($_SERVER['QUERY_STRING'] != "")) {
      $logoutAction.= "&amp;" . htmlentities($_SERVER['QUERY_STRING']);
  }
  
  if ((isset($_GET['doLogout'])) &amp;&amp; ($_GET['doLogout'] == "true")) {
  
      // to fully log out a visitor we need to clear the session varialbles
  
      $_SESSION['MM_Username'] = NULL;
      $_SESSION['MM_UserGroup'] = NULL;
      $_SESSION['PrevUrl'] = NULL;
      unset($_SESSION['MM_Username']);
      unset($_SESSION['MM_UserGroup']);
      unset($_SESSION['PrevUrl']);
      $logoutGoTo = "/supsrwk_epenyenggaraan/stafflogin.php";
      if ($logoutGoTo) {
          header("Location: $logoutGoTo");
          exit;
      }
  }
  
  ?&gt;
  
  &lt;?php
  include ("supsrwk_epenyenggaraan.php");
   ?&gt;
  &lt;?php
  
  // initialize the session
  
  if (!isset($_SESSION)) {
      session_start();
  }
  
  if (!function_exists("GetSQLValueString")) {
      function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
      {
          if (PHP_VERSION &lt; 6) {
              $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
          }
  
          $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
          switch ($theType) {
          case "text":
              $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
              break;
  
          case "long":
          case "int":
              $theValue = ($theValue != "") ? intval($theValue) : "NULL";
              break;
  
          case "double":
              $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
              break;
  
          case "date":
              $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
              break;
  
          case "defined":
              $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
              break;
          }
  
          return $theValue;
      }
  }
  
  $editFormAction = $_SERVER['PHP_SELF'];
  
  if (isset($_SERVER['QUERY_STRING'])) {
      $editFormAction.= "?" . htmlentities($_SERVER['QUERY_STRING']);
  }
  
  if ((isset($_POST["MM_update"])) &amp;&amp; ($_POST["MM_update"] == "form1")) {
      $updateSQL = sprintf("UPDATE aduan SET statusAduan=%s WHERE aduanID=%s", GetSQLValueString($_POST['statusAduan'], "text") , GetSQLValueString($_POST['aduanID'], "int"));
      mysql_select_db($database_supsrwk_epenyenggaraan, $supsrwk_epenyenggaraan);
      $Result1 = mysql_query($updateSQL, $supsrwk_epenyenggaraan) or die(mysql_error());
      $updateGoTo = "/supsrwk_epenyenggaraan/rekodDalamProses.php?aduanID=" . $row_aduan['aduanID'] . "";
      if (isset($_SERVER['QUERY_STRING'])) {
          $updateGoTo.= (strpos($updateGoTo, '?')) ? "&amp;" : "?";
          $updateGoTo.= $_SERVER['QUERY_STRING'];
      }
  
      header(sprintf("Location: %s", $updateGoTo));
  }
  
  $colname_staff = "-1";
  
  if (isset($_SESSION['MM_Username'])) {
      $colname_staff = $_SESSION['MM_Username'];
  }
  
  mysql_select_db($database_supsrwk_epenyenggaraan, $supsrwk_epenyenggaraan);
  $query_staff = sprintf("SELECT * FROM staff WHERE No_KP = %s", GetSQLValueString($colname_staff, "text"));
  $staff = mysql_query($query_staff, $supsrwk_epenyenggaraan) or die(mysql_error());
  $row_staff = mysql_fetch_assoc($staff);
  $totalRows_staff = "-1";
  
  if (isset($_SESSION['MM_Username'])) {
      $totalRows_staff = $_SESSION['MM_Username'];
  }
  
  mysql_select_db($database_supsrwk_epenyenggaraan, $supsrwk_epenyenggaraan);
  $query_staff = sprintf("SELECT * FROM staff WHERE No_KP = %s", GetSQLValueString($colname_staff, "text"));
  $staff = mysql_query($query_staff, $supsrwk_epenyenggaraan) or die(mysql_error());
  $row_staff = mysql_fetch_assoc($staff);
  $totalRows_staff = mysql_num_rows($staff);
  $maxRows_aduan = 10;
  $pageNum_aduan = 0;
  
  if (isset($_GET['pageNum_aduan'])) {
      $pageNum_aduan = $_GET['pageNum_aduan'];
  }
  
  $startRow_aduan = $pageNum_aduan * $maxRows_aduan;
  mysql_select_db($database_supsrwk_epenyenggaraan, $supsrwk_epenyenggaraan);
  $query_aduan = "SELECT * FROM aduan WHERE statusAduan = 'PERMOHONAN'";
  $query_limit_aduan = sprintf("%s LIMIT %d, %d", $query_aduan, $startRow_aduan, $maxRows_aduan);
  $aduan = mysql_query($query_limit_aduan, $supsrwk_epenyenggaraan) or die(mysql_error());
  $row_aduan = mysql_fetch_assoc($aduan);
  
  if (isset($_GET['totalRows_aduan'])) {
      $totalRows_aduan = $_GET['totalRows_aduan'];
  }
  else {
      $all_aduan = mysql_query($query_aduan);
      $totalRows_aduan = mysql_num_rows($all_aduan);
  }
  
  $totalPages_aduan = ceil($totalRows_aduan / $maxRows_aduan) - 1;
  </code></pre>