title: PHP MySQL Multiple Forms and Multiple Submits on single page
body: <p>I am trying to filter use a form to filter a database then provide a way to update the filtered data.  I may not being doing it the best way, but it is close to working.  The problem seems to be that when I press the "Update" button, a few variables are cleared; count and ID.</p>
  
  <p>I have fixed count by making it a session variable, but there isn't a way to do it with ID.  I am not sure why count gets erased, so I would appreciate if someone could tell me.  </p>
  
  <p>The update part of my code works perfectly when used without the filter part, again, the problem is that the id variable is empty.  I have tested all other variables and put a constant in for ID for testing in my update statement.  Here is my code.</p>
  
  <pre><code>&lt;?php
  session_start();
  ?&gt;
  
  &lt;?php
  $host="localhost"; // Host name 
  $username=""; // Mysql username 
  $password=""; // Mysql password 
  $db_name="inventory"; // Database name 
  $tbl_name="computers"; // Table name
  // Connect to server and select databse.
  mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
  
  mysql_select_db("$db_name")or die("cannot select DB");
  
  // Get values from form 
  $school=$_POST['school'];
  $make=$_POST['make'];
  $model=$_POST['model'];
  $barcode=$_POST['barcode'];
  $location=$_POST['location'];
  ?&gt;
  
      &lt;?php
      include 'nav-bar.php';
      ?&gt;
  
      &lt;h2 align="center"&gt;Filter Computers&lt;/h2&gt;
      &lt;form name="form" method="post" style="margin: 0; text-align: center;"&gt;
      &lt;p&gt;&lt;label&gt;School Name:&lt;/label&gt;&lt;input type="text" name="school" size="8" id="school" tabindex="1"&lt;/p&gt;
      &lt;p&gt;&lt;label&gt;Make:&lt;/label&gt;&lt;input type="text" name="make" size="25" id="make" tabindex="1"&lt;/p&gt;
      &lt;p&gt;&lt;label&gt;Model:&lt;/label&gt;&lt;input type="text" name="model" size="25" id="model" tabindex="1"&lt;/p&gt;
      &lt;p&gt;&lt;label&gt;Barcode:&lt;/label&gt;&lt;input type="text" name="barcode" size="12" id="barcode" tabindex="1"&lt;/p&gt;
      &lt;p&gt;&lt;label&gt;Location:&lt;/label&gt;&lt;input type="text" name="location" size="25" id="location" tabindex="1"&lt;/p&gt;
      &lt;p&gt;&lt;label&gt;Serial:&lt;/label&gt;&lt;input type="text" name="serial" size="25" id="location" tabindex="1"&lt;/p&gt;
      &lt;p&gt;&lt;label&gt;Date Acquired yyyy-dd-mm:&lt;/label&gt;&lt;input type="text" name="date" size="8" id="location" tabindex="1"&lt;/p&gt;
      &lt;p&gt;&lt;label&gt;Processor:&lt;/label&gt;&lt;input type="text" name="processor" size="25" id="location" tabindex="1"&lt;/p&gt;
      &lt;p&gt;&lt;label&gt;RAM:&lt;/label&gt;&lt;input type="text" name="ram" size="25" id="location" tabindex="1"&lt;/p&gt;
      &lt;p&gt;&lt;input align="center" type="submit" name="Filter" value="Filter"&gt;
      &lt;/form&gt;
  
      &lt;?php
  
      if($_POST['Filter']){
      $sql = "SELECT * FROM $tbl_name WHERE school like '%$school' AND make like '%$make' AND model like '%$model' AND location like '%$location'";
      $result=mysql_query($sql);
  
      // Count table rows 
      $count=mysql_num_rows($result);
      $_SESSION['count']=$count;
  
  
      ?&gt;
  
      &lt;strong&gt;Update Multiple Computers&lt;/strong&gt;&lt;br&gt; 
      &lt;table width="500" border="0" cellspacing="1" cellpadding="0"&gt;
      &lt;form name="form1" method="post" action=""&gt;
      &lt;tr&gt; 
      &lt;td&gt;
      &lt;table width="500" border="0" cellspacing="1" cellpadding="0"&gt;
  
  
      &lt;tr&gt;
      &lt;td align="center"&gt;&lt;strong&gt;Id&lt;/strong&gt;&lt;/td&gt;
      &lt;td align="center"&gt;&lt;strong&gt;School&lt;/strong&gt;&lt;/td&gt;
      &lt;td align="center"&gt;&lt;strong&gt;Make&lt;/strong&gt;&lt;/td&gt;
      &lt;td align="center"&gt;&lt;strong&gt;Model&lt;/strong&gt;&lt;/td&gt;
      &lt;td align="center"&gt;&lt;strong&gt;Barcode&lt;/strong&gt;&lt;/td&gt;
      &lt;td align="center"&gt;&lt;strong&gt;Location&lt;/strong&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;?php
      while($rows=mysql_fetch_array($result)){
      ?&gt;
      &lt;tr&gt;
      &lt;td align="center"&gt;&lt;?php $id[]=$rows['id']; ?&gt;&lt;?php echo $rows['id']; ?&gt;&lt;/td&gt;
      &lt;td align="center"&gt;&lt;input name="school[]" type="text" id="school" value="&lt;?php echo $rows['school']; ?&gt;"&gt;&lt;/td&gt;
      &lt;td align="center"&gt;&lt;input name="make[]" type="text" id="make" value="&lt;?php echo $rows['make']; ?&gt;"&gt;&lt;/td&gt;
      &lt;td align="center"&gt;&lt;input name="model[]" type="text" id="model" value="&lt;?php echo $rows['model']; ?&gt;"&gt;&lt;/td&gt;
      &lt;td align="center"&gt;&lt;input name="barcode[]" type="text" id="barcode" value="&lt;?php echo $rows['barcode']; ?&gt;"&gt;&lt;/td&gt;
      &lt;td align="center"&gt;&lt;input name="location[]" type="text" id="location" value="&lt;?php echo $rows['location']; ?&gt;"&gt;&lt;/td&gt;
      &lt;/tr&gt;
  
      &lt;?php
      }
      ?&gt;
      &lt;tr&gt;
      &lt;td colspan="4" align="center"&gt;&lt;input type="submit" name="Update" value="Update"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;/table&gt;
      &lt;/td&gt;
      &lt;/tr&gt;
      &lt;/form&gt;
      &lt;/table&gt;
      &lt;?php
      }
      // Check if button name "Update" is active, do this 
      if(isset($_POST['Update'])){
      for($i=0;$i&lt;$_SESSION['count'];$i++){
      $sql1="UPDATE $tbl_name SET school='$school[$i]', make='$make[$i]', model='$model[$i]' , barcode='$barcode[$i]' , location='$location[$i]' WHERE id='$id[$i]'";
      $result1=mysql_query($sql1);
      }
      session_destroy();
      }
      if(isset($result1)){
      echo "&lt;meta http-equiv=\"refresh\" content=\"0;URL=update_multiple.php\"&gt;";
      }
      ?&gt;`
  </code></pre>
  
  <p>Any help is surely appreciated.</p>