title: Update a row value in SQL database after submit based on selected checkbox(es)
body: <p>I have this table:</p>
  
  <p><img src="https://i.stack.imgur.com/bg2xI.png" alt="enter image description here"></p>
  
  <p>In my SQL, I have this column named 'Status' with two values only: Inactive and Active which is set to be Inactive by default.</p>
  
  <p>My question is, how can I update in my database the 'Status' column to "Active" if the specific row is checked after clicking the "Submit" button? Even if there's more than 1 row that is checked. What SQL query should I use (or if combined with PHP)?</p>
  
  <p>I am using PHP by the way. I've researched and can't seem to get the right answer.</p>
  
  <p>Thank you in advance for all the help/advice/suggestion.</p>
  
  <p><strong>UPDATE</strong>:</p>
  
  <p>I have modified @Vikas Umrao's answer and made a few changes. The Status row successfully updates whenever the table row is checked. However, the row that was previously updated stays in the array and does not reset. I'll explain it further, but before that, below are my working code with database:</p>
  
  <p><strong>SQL</strong> (set up your own connection, mine is named database.php) </p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS `table_test` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `name` varchar(255) NOT NULL,
  `department` varchar(255) NOT NULL,
  `status` varchar(255) NOT NULL,
  PRIMARY KEY (`id`)
  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8 AUTO_INCREMENT=4 ;
  
  INSERT INTO `table_test` (`id`, `name`, `department`, `status`) VALUES
  (1, 'Misha', 'Accounting', 'Inactive'),
  (2, 'Justin', 'IT', 'Inactive'),
  (3, 'Chris', 'HR', 'Inactive');
  </code></pre>
  
  <p>And this is my whole index.php as some script based on Vikas'</p>
  
  <pre><code>&lt;?php
  include('database.php');
  
  $query = "SELECT * FROM table_test";
  $result = mysql_query($query);
  
  if($result === false) { 
      die(mysql_error());
  }
  
  echo "&lt;form method='post' action='#'&gt;
          &lt;h2&gt;Table Content&lt;/h2&gt;
              &lt;table&gt;
                  &lt;thead&gt;
                      &lt;tr style='background-color: rgb(102, 222, 93);'&gt;                            
                          &lt;td&gt;Name&lt;/td&gt;
                          &lt;td&gt;Department&lt;/td&gt;
                          &lt;td&gt;Status&lt;/td&gt;
                          &lt;td&gt;&lt;/td&gt;
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;";
  
  while($row = mysql_fetch_array($result)){
  
      $row_id = $row['id'];
      $name = $row['name'];
      $department = $row['department'];
      $status = $row['status'];
  
      echo "&lt;tr&gt;&lt;td&gt;" . $name . "&lt;/td&gt;&lt;td&gt;" . $department . "&lt;/td&gt;&lt;td&gt;" . $status . "&lt;/td&gt;&lt;td&gt;&lt;input type='checkbox' name='id[]' value='" . $row_id . "'/&gt;&lt;/td&gt;&lt;/tr&gt;";
  }
  
  echo "&lt;/tbody&gt;&lt;/table&gt;&lt;input type='submit' value='submit'&gt;&lt;/form&gt;"; //end form
  
  /***** Update Status *****/
  
  /*print_r($_POST);*/
      if(gettype($_POST['id'])=="array"){
          foreach($_POST['id'] as $val){
           $id_c = $val;
           $query2 = "UPDATE table_test SET status = 'Inactive' where id='".$id_c."'";
           $result2 = mysql_query($query2);
           if($result2 === false) { 
              die(mysql_error());
           }
           echo "Status " .$id_c. " is updated. &lt;br&gt;";
          }
      }   
      mysql_close();
  ?&gt;
  </code></pre>
  
  <p>UPDATE QUESTION: </p>
  
  <p>When I check a row and then click submit, the status value in database changes. I echoed the result of which IDs are updated. However, even after refreshing the page, the data row updated values were still there. </p>
  
  <p>So let's say I change the Update query to active instead of inactive, if I refresh the page and the previously updated rows were Misha and Chris', then their status will be active even if I don't want them to:</p>
  
  <pre><code>$query2 = "UPDATE table_test SET status = 'Active' where id='".$id_c."'";
  </code></pre>
  
  <p>So everytime I refresh the page, it will continuously update the row even if it's not checked. How can I clear the php array values? I've seen this the unset and instantiate but can't seem to apply it here. How should I do that?</p>
  
  <p>Below is a sample screenshot of the result:</p>
  
  <p><img src="https://i.stack.imgur.com/bBHbH.png" alt="enter image description here"></p>
  
  <p>Thank you!</p>
  
  <p>=======================</p>
  
  <p>FINAL:</p>
  
  <p>I was able to fix it on my own. Thanks everyone!        </p>