title: Edit/delete/list in one page
body: <p>I am trying to make a page with all the information from a database, where a user would be able to edit or delete rows. I don't quite understand how to make the buttons work. I am a beginner in programming, would be really grateful if you could help me.</p>
  
  <p>My code:</p>
  
  <pre><code>&lt;form action="" method="post"&gt;
  &lt;?php
  $sqlquery="SELECT artistId, firstname, lastname, nationality, dateofBirth, otherInfo, image  from $artists order by 1";
  $result = mysqli_query($connect, $sqlquery);
  if($result)
  {
  echo "&lt;table id=\"artists\"&gt;";
  
                  while  ($sqlRow=mysqli_fetch_array($result, MYSQL_ASSOC)) 
                  {
  
  
                      echo "&lt;tr&gt;";
                      echo "&lt;td&gt;";
                      echo"&lt;input type=\"text\" name=\"textid[]\" value=\"".$sqlRow['artistId']."\"/&gt;"; 
                      echo "&lt;/td&gt;";
                      echo "&lt;td&gt;";
                      echo "&lt;input type=\"text\" name=\"textfirstname[]\" value=\"".$sqlRow['firstname']."\"/&gt;";
                      echo "&lt;/td&gt;";
                      echo "&lt;td&gt;";
                      echo "&lt;input type=\"text\" name=\"textlastname[]\" value=\"".$sqlRow['lastname']."\"/&gt;";
                      echo "&lt;/td&gt;";
                      echo "&lt;td&gt;";
                      echo "&lt;input type=\"text\" name=\"textnation[]\" value=\"".$sqlRow['nationality']."\"/&gt;";
                      echo "&lt;/td&gt;";
                      echo "&lt;td&gt;";
                      echo "&lt;input type=\"text\" name=\"textdateofbirth[]\" value=\"".$sqlRow['dateofBirth']."\"/&gt;";
                      echo "&lt;/td&gt;";
                      echo "&lt;td&gt;";
                      echo "&lt;input type=\"text\" name=\"textotherinfo[]\" value=\"".$sqlRow['otherInfo']."\"/&gt;";
                      echo "&lt;/td&gt;";
                      echo "&lt;td&gt;";
                      echo "&lt;input type=\"text\" name=\"textimage[]\" value=\"".$sqlRow['image']."\"/&gt;";
                      echo "&lt;/td&gt;";
                      echo "&lt;td&gt;";
                      echo "&lt;input type=\"submit\" onclick=\"return confirm('Edit the record?')\" name=\"edit[]\" value=\"Edit\" /&gt;";
                      echo "&lt;input type=\"submit\" name=\"delete[]\" value=\"Delete\" onclick=\"return confirm('Delete the record?')\"/&gt;";
                      echo "&lt;input type=\"reset\" name=\"reset[]\" value=\"Cancel\" /&gt;";
                      echo "&lt;/td&gt;";
                      echo "&lt;/tr&gt;";
                      }
  
  
  }
  print '&lt;/table&gt;';
  
  if($_POST)
  {
  $artistId=$_POST['textid'];
  $fname=$_POST['textfirstname'];
  $lname=$_POST['textlastname'];
  $nation=$_POST['textnation'];
  $dateofBirth=$_POST['textdateofbirth'];
  $otherInfo=$_POST['textotherinfo'];
  $image=$_POST['textimage'];
  
  
  for($i=0;$i&lt;sizeof($artistId);$i++)
  {
  if (isset($_POST['edit[$i]']))
  {
  $query="UPDATE $artists set artistId='".$artistId[$i]."', firstname='".$fname[$i]."', lastname='".$lname[$i]."', nationality='".$nation[$i]."', dateofBirth='".$dateofBirth[$i]."', otherInfo='".$otherInfo[$i]."', image='".$image[$i]."' WHERE (artistId='".$sqlRow['artistId']."')";
  }
  
  }
  }
  ?&gt;
  </code></pre>