title: PHP/MYSQL How to Insert/Update Multiple Tables
body: <p>I am trying to update a database using a form, but its not adding the item or updating. Deleting the item works but that's it. What am I doing wrong and how can I do to resolve this? </p>
  
  <p><img src="https://i.stack.imgur.com/jFDPG.jpg" alt="enter image description here">
  Thank You in advance your assistance is appreciated.</p>
  
  <p><strong>INSERT ITEM PAGE</strong></p>
  
  <pre><code>  &lt;?php 
  // Parse the form data and add inventory item to the system
  if (isset($_POST['PART_DESC'])) {
  
  
               $PART_DESC = $row["PART_DESC"];
               $SERIAL_NUM = $row["SERIAL_NUM"];
               $RACK_NUM = $row["RACK_NUM"];
               $PART_TYPE_ID = $row["PART_TYPE_ID"];
               $PART_TYPE_DESC = $row["PART_TYPE_DESC"];
      // See if that product name is an identical match to another product in the system
      $sql = mysql_query("SELECT PART_ID FROM PART WHERE ='$PART_ID' LIMIT 1");
      $productMatch = mysql_num_rows($sql); // count the output amount
      if ($productMatch &gt; 0) {
          echo 'Sorry you tried to place a duplicate "Product Name" into the system, &lt;a href="inventory.php"&gt;click here&lt;/a&gt;';
          exit();
      }
      // Add this product into the database now
      $sql = mysql_query("INSERT INTO PART (PART_DESC, SERIAL_NUM, RACK_NUM, PART_TYPE_DESC, LOCATION) 
          VALUES('$PART_DESC','$SERIAL_NUM','$RACK_NUM','$PART_TYPE_ID','$PART_TYPE_DESC',now() )") or die (mysql_error());
       $pid = mysql_insert_id();
  
      exit();
  }
  
  ?&gt;
  
  &lt;?php 
  // Script Error Reporting
  error_reporting(E_ALL);
  ini_set('display_errors', '1');
  ?&gt;
  </code></pre>
  
  <p><strong>EDIT ITEM PAGE</strong></p>
  
  <pre><code>&lt;?php 
  // Gather this product's full information for inserting automatically into the edit form below on page
  if (isset($_GET['pid'])) {
      $targetID = $_GET['pid'];
      $sql = mysql_query("SELECT PART_ID, PART_DESC, SERIAL_NUM, RACK.RACK_NUM, PART.PART_TYPE_ID, PART_TYPE_DESC, LOCATION
  FROM PART
  INNER JOIN PART_TYPE ON PART.PART_TYPE_ID = PART_TYPE.PART_TYPE_ID
  INNER JOIN RACK ON RACK.RACK_NUM = PART.RACK_NUM
  WHERE PART_ID='$targetID' LIMIT 1");
      $productCount = mysql_num_rows($sql); // count the output amount
      if ($productCount &gt; 0) {
          while($row = mysql_fetch_array($sql)){ 
  
               $id = $row["PART_ID"];
               $PART_DESC = $row["PART_DESC"];
               $SERIAL_NUM = $row["SERIAL_NUM"];
               $RACK_NUM = $row["RACK_NUM"];
               $PART_TYPE_ID = $row["PART_TYPE_ID"];
               $PART_TYPE_DESC = $row["PART_TYPE_DESC"];
               $LOCATION = $row["LOCATION"];
          }
      } else {
          echo "Sorry dude that crap dont exist.";
          exit();
      }
  }
  ?&gt;
  &lt;?php 
  // Parse the form data and add inventory item to the system
  if (isset($_POST['PART_DESC'])) {
  
      $pid = mysql_real_escape_string($_POST['thisID']);
  
               $PART_DESC = $row["PART_DESC"];
               $SERIAL_NUM = $row["SERIAL_NUM"];
               $RACK_NUM = $row["RACK_NUM"];
               $PART_TYPE_ID = $row["PART_TYPE_ID"];
               $PART_TYPE_DESC = $row["PART_TYPE_DESC"];
               $LOCATION = $row["LOCATION"];
  
      // See if that product name is an identical match to another product in the system
      $sql = mysql_query("UPDATE PART SET PART_DESC='$PART_DESC', SERIAL_NUM='$SERIAL_NUM', PART.PART_TYPE_DESC='$PART_TYPE_DESC', RACK.RACK_NUM='$RACK_NUM', LOCATION='$LOCATION' 
      INNER JOIN PART_TYPE ON PART.PART_TYPE_ID = PART_TYPE.PART_TYPE_ID
  INNER JOIN RACK ON RACK.RACK_NUM = PART.RACK_NUM WHERE PART.PART_ID='$pid'");
      header("location: inventory.php"); 
      exit();
  }
  </code></pre>
  
  <p>?></p>