title: How to edit specific table records with own Admin Panel?
body: <p>I simplified my code from bullshit, so we can find the problem easier.</p>
  
  <p>I have a table with record from a db. I can insert new, delete an existing, but somehow I can not modify them.</p>
  
  <p>When I Click the Edit button, the good one appears, but when I edit it and click the Change button, always the last row changes whatewer I tried to modofy.</p>
  
  <p>Sorry for my english, I write an example:</p>
  
  <p>Dog
  Cat
  Car
  Chair</p>
  
  <p>If I edit the Cat, the Chair will change... Very frustrating :D</p>
  
  <p>Here is my code:</p>
  
  <pre><code>&lt;table&gt;
  &lt;tr&gt;
    &lt;th&gt;ID&lt;/th&gt;
    &lt;th&gt;Title&lt;/th&gt;
    &lt;th&gt;Edit&lt;/th&gt;
    &lt;th&gt;Delete&lt;/th&gt;
  &lt;/tr&gt;
  
  &lt;?php 
  include("connect.php");
  
  $get_cats = "SELECT * FROM categories";
  $run_cats = mysqli_query($con, $get_cats);
  
  while ($row_cats = mysqli_fetch_array($run_cats)) {
    $cat_id     = $row_cats['cat_id'];
    $cat_title  = $row_cats['cat_title'];
  ?&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;?php echo $cat_id; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;?php echo $cat_title; ?&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href="index.php?manage_cats&amp;edit_cat=&lt;?php echo $cat_id; ?&gt;"&gt;Edit&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href="index.php?manage_cats&amp;delete_cat=&lt;?php echo $cat_id; ?&gt;"&gt;Delete&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;?php } ?&gt; &lt;!-- end while --&gt;
  
    &lt;tr&gt;
      &lt;td&gt;Insert New Category&lt;/td&gt;
      &lt;td colspan="2"&gt;&lt;input type="text" name="insert_cat_title" /&gt;&lt;/td&gt;
      &lt;td&gt;&lt;input type="submit" name="insert_cat" value="Insert"&gt;&lt;/td&gt;
    &lt;/tr&gt;
  
    &lt;?php
    if(isset($_GET['edit_cat'])) {
      $edit_id     = $_GET['edit_cat'];
      $get_cat     = "SELECT * FROM categories WHERE cat_id = '$edit_id'";
      $run_cat_new = mysqli_query($con, $get_cat);
  
      while ($row_cat = mysqli_fetch_array($run_cat_new)) {
        $cat_id    = $row_cat['cat_id'];
        $cat_title = $row_cat['cat_title'];
    ?&gt;
        &lt;tr&gt;
          &lt;td&gt;Change Category Name&lt;/td&gt;
          &lt;td colspan="2"&gt;&lt;input type="text" name="update_cat_title" value="&lt;?php echo $cat_title; ?&gt;"/&gt;&lt;/td&gt;
          &lt;td&gt;&lt;input type="submit" name="update_cat" value="Change"&gt;&lt;/td&gt;
        &lt;/tr&gt;
    &lt;?php } } ?&gt;
  
  &lt;/table&gt;
  &lt;/form&gt;
  
  &lt;?php 
  
  // Insert Category
  if(isset($_POST['insert_cat'])) {
  $cat_title = $_POST['insert_cat_title'];
  
  if($cat_title == '') {
    echo "&lt;script&gt;alert('Please insert Category Name')&lt;/script&gt;";
    echo "&lt;script&gt;window.open('index.php?manage_cats', '_self')&lt;/script&gt;";
  }
  else {
  $insert_cat = "INSERT INTO categories (cat_title) VALUES ('$cat_title')";
  $run_cat    = mysqli_query($con, $insert_cat);
  echo "&lt;script&gt;window.open('index.php?manage_cats', '_self')&lt;/script&gt;";
  }
  }
  
  // Delete Category
  if(isset($_GET['delete_cat'])) {
  $delete_id  = $_GET['delete_cat'];
  $delete_cat = "DELETE FROM categories WHERE cat_id = '$delete_id'";
  $run_delete = mysqli_query($con, $delete_cat);
  echo "&lt;script&gt;window.open('index.php?manage_cats', '_self')&lt;/script&gt;";
  }
  
  // Edit Category
  if(isset($_POST['update_cat'])) {
  $cat_title_new  = $_POST['update_cat_title'];
  
  if($cat_title == '') {
    echo "&lt;script&gt;alert('Please insert Category Name')&lt;/script&gt;";
    echo "&lt;script&gt;window.open('index.php?manage_cats&amp;edit_cat', '_self')&lt;/script&gt;";
  }
  else {
    $update_cat     = "UPDATE categories SET cat_title = '$cat_title_new' WHERE cat_id = '$cat_id'";
    $run_update     = mysqli_query($con, $update_cat);
    echo "&lt;script&gt;window.open('index.php?manage_cats', '_self')&lt;/script&gt;";
  }
  }
  ?&gt;
  </code></pre>