title: Update Multiple Rows at Once in PHP
body: <p>I want to display table of student in "Class 1". User can change the information and update it into database. I want to update multiple rows at a time, but it ends up updating only 1 row (the last row). Please help me .. how should i change the code in order to update multiple rows at once, when i click on update. Thanks.</p>
  
  <p>This is the code:</p>
  
  <pre><code>&lt;?php
  define('DB_SERVER', 'localhost');
  define('DB_USERNAME', 'root');
  define('DB_PASSWORD', '');
  define('DB_DATABASE', 'test');
  
  $connection = mysql_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD) or die(mysql_error());
  $database = mysql_select_db(DB_DATABASE) or die(mysql_error());
  mysql_set_charset("utf8", $connection);
  ?&gt;
  
      &lt;form action='update.php' method='post'&gt;
      &lt;table border='1'&gt;
          &lt;?php
              $result = mysql_query("SELECT * FROM student WHERE class = 1 ");
  
                      echo "&lt;tr&gt;";
                          echo "&lt;td colspan='3'&gt;CLASS 1&lt;/td&gt;";
                      echo "&lt;/tr&gt;";
  
                      while($row = mysql_fetch_array($result)){
  
                      echo "&lt;tr&gt;";
                          echo "&lt;td&gt;&lt;input type='hidden' name='id' value='".$row['id']."' /&gt;&lt;/td&gt;";
                          echo "&lt;td&gt;name  :&lt;input type='text' name='name' value='".$row['name']."' /&gt;&lt;/td&gt;";
                          echo "&lt;td&gt;Sex  :&lt;input type='text' name='sex' value='".$row['sex']."' /&gt;&lt;/td&gt;";
                          echo "&lt;td&gt;Age  :&lt;input type='text' name='age' value='".$row['age']."' /&gt;&lt;/td&gt;";
                      echo "&lt;/tr&gt;";
  
              }
  
              echo "&lt;input type='submit' name='update' value='UPDATE' /&gt;";
          ?&gt;
      &lt;table&gt;
  &lt;/form&gt;
  
  &lt;?php
  
  if(isset($_POST['update'])){
      $id  = $_POST['id'];
      $name= $_POST['name'];
      $sex = $_POST['sex'];
      $age = $_POST['age'];
  
      mysql_query("   UPDATE student
                         SET name= '$name', sex='$sex', age='$age'
                       WHERE id = '$id' ");   
  
      header("location: update.php");
      exit;
  }   
  
  ?&gt;
  </code></pre>
  
  <p>
  <img src="https://i.stack.imgur.com/qqxLd.png" alt="form"></p>