title: Update multiple row using PHP and MySQL
body: <p>I'm new to php and mySql. I'm trying to update multiple row by using php and mysql. </p>
  
  <p>I'm having problem with updating multiple row in MySQL database. It's only update the last row  of the table in the database. For example, user click on view product. The page will list 10 product that currently in the database. And user wants to update product information by on-click method. After finishing update, user click submit. </p>
  
  <p>The problem is it only capture and update information of the last product in the table. I tried to put it in the foreach() function. But it doesnt work. </p>
  
  <p>Please help. I just learned PHP and mySQL less than a week. I very much appreciate any helps.</p>
  
  <pre><code>&lt;?php
  include 'dbconn.inc.php';
  include 'functions.inc.php';
  
  $sql = "SELECT * FROM products";
  $res = $mysqli-&gt;query($sql);
  
  while( $row = $res-&gt;fetch_array(MYSQLI_ASSOC) ){
  $products($row['id']) = 'id';
  }
  
  $id = $mysqli-&gt;real_escape_string( $_POST['id'] );
  $weight = $mysqli-&gt;real_escape_string( $_POST['weight'] );
  $name = $mysqli-&gt;real_escape_string( $_POST['name'] );
  $supplier_id = $mysqli-&gt;real_escape_string( $_POST['supplier_id'] );
  $price = $mysqli-&gt;real_escape_string( $_POST['price'] );
  $description = $mysqli-&gt;real_escape_string( $_POST['description'] );
  
  foreach( $products as $id){
  $sql = "UPDATE products
      SET
          `id` = '$id',
          `weight` = '$weight',
          `price` = '$price',
          `name` = '$name',
          `supplier_id` = '$supplier_id',
          `description` = '$description'
  
      WHERE `id` = '$id'";
  
   }
  </code></pre>