title: How to edit table values in MySQL and PHP?
body: <p>I have that people can add team names to my MySQL table. Now I want them to edit it. I have tried several tutorials but i can't figure it out. I like to know what i am doing wrong.</p>
  
  <p>This is my admin.php:</p>
  
  <pre><code>&lt;?php
      $username = "root";
      $password = "";
      $hostname = "localhost";
  
      $dbhandle = mysql_connect($hostname, $username, $password) or die("Could not connect to database");
  
      $selected = mysql_select_db("login", $dbhandle);
  
  
  
          if(isset($_POST['team'])){
              $team = $_POST['team'];
              $ID = $_POST['id'];         
  
              $query = mysql_query("SELECT * FROM e2teams WHERE Team='$team' and ID='$ID'");
              if(mysql_num_rows($query) &gt; 0 ) { //check if there is already an entry for that username
                  echo "$team bestaat al!";
              }
              else{
                  mysql_query("INSERT INTO e2teams (Team) VALUES ('$team')");
                  header("location:e2admin.php");
              }
      }
  
      mysql_close();
  ?&gt;
  
  &lt;html&gt;
      &lt;body&gt;
          &lt;h1&gt;Add teams&lt;/h1&gt;
              &lt;form action="e2admin.php" method="POST"&gt;
                  &lt;input type="text" name="team" placeholder="Team naam" /&gt;&lt;br&gt;
                  &lt;input type="submit" value="Toevoegen" /&gt;
              &lt;/form&gt;
  
              &lt;?php
                  $table = "e2teams";
                  $sql = "SELECT * FROM e2teams";
                  $result = mysql_query($sql, $dbhandle);
                  if(mysql_num_rows($result) &gt; 0){
                      while($row = mysql_fetch_array($result)) {
                          echo $row['Team']. "&lt;a href='edit.php?edit=$row[1]'&gt;Bewerk&lt;/a&gt;&lt;br&gt;";
                      }
                  }
              ?&gt;
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>The add teams works. but the edit button doesn't work yet. If I click on edit I go to the edit.php page; here I want to add the new name and need the Team to change in the MySQL row.</p>
  
  <p>This is my edit.php:</p>
  
  <pre><code>&lt;?php
      $username = "root";
      $password = "";
      $hostname = "localhost";
  
      $dbhandle = mysql_connect($hostname, $username, $password) or die("Could not connect to database");
  
      $selected = mysql_select_db("login", $dbhandle);
  
      if( isset($_GET['edit'])) {
          $id = $_GET['edit'];
          $res = mysql_query("SELECT * FROM e2teams");
          $row= mysql_fetch_array($res);
      }
  
      if (isset ($_POST['nieuwenaam'])) {
          $newname = $_POST['nieuwenaam'];
          $id = $_POST['id'];
          $sql = "UPDATE e2teams SET Team='$newname' WHERE id='$id'";
          $res = mysql_query($sql) or die ("Fout bij updaten".mysql_error());
          echo "&lt;meta http-equiv='refresh' content='0;url=edit.php'&gt;";
      }
  ?&gt;      
  
  
  &lt;html&gt;
  &lt;body&gt;       
  
  
              &lt;form action="edit.php" method="POST"&gt;
                  &lt;input type="text" name="nieuwenaam" placeholer="test" /&gt;&lt;br&gt;
                  &lt;input type="hidden" name="id" placeholder="idnaam" value"s" /&gt;&lt;br&gt;
                  &lt;input type="submit" value="Update" /&gt;
              &lt;/form&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I also like to know how to delete team names but this is maybe for a next question.</p>