title: Update multiple fields of a mysql database using a php form
body: <p>I want to to pull all fields from a row in my table into a form, update them, and post them back to the database.  This is what I have, everything from my table row is pulling into the form but when I update I get undefined variable for $row.</p>
  
  <pre><code>&lt;?php
  include("header.php");
  include("config.php"); 
  if( isset($_GET['edit']))
  {
          $id = $_GET['edit'];
          $result= mysql_query("SELECT * FROM customers");
          $row= mysql_fetch_array($result);
  }
  if ( isset($_POST['id'], $_POST['fName'], $_POST['lname'], $_POST['telNum'], $_POST['address'], $_POST['city'], $_POST['state'], $_POST['zip'], $_POST['email'], $_POST['service'], $_POST['notes']))
  {
      $id = $_POST['id'];
      $fName = $_POST['fName'];
      $lName = $_POST['lName'];
      $telNum = $_POST['telNum'];
      $address = $_POST['address'];
      $city = $_POST['city'];
      $state = $_POST['state'];
      $zip = $_POST['zip'];
      $email =$_POST['email'];
      $service = $_POST['service'];
      $notes = $_POST['notes'];
      $sqlFn = "UPDATE customers SET fName = $fname WHERE id = $id";
      $sqlLn = "UPDATE customers SET lName = $lName WHERE id = $id";
      $sqlTelNum = "UPDATE customers SET telNum = $telNum WHERE id = $id";
      $sqlAddress = "UPDATE customers SET address = $address WHERE id = $id";
      $sqlCity = "UPDATE customers SET city = $city WHERE id = $id";
      $sqlState = "UPDATE customers SET state = $state WHERE id = $id";   
      $sqlZip = "UPDATE customers SET zip = $zip WHERE id = $id";
      $sqlEmail = "UPDATE customers SET email = $email WHERE id = $id";
      $sqlService = "UPDATE customers SET service = $service WHERE id = $id";
      $sqlNotes = "UPDATE customers SET notes = $notes WHERE id = $id";
      $result = mysql_query($sqlFn, $sqlLn, sqlTelNum, sqlAdress, sqlCity, 
                            sqlState, sqlZip, sqlEmail, sqlService, sqlNotes)
                            or die("Could not update".mysql_error());
          echo "&lt;meta http-equiv='refresh' content='0;url=viewClients.php'&gt;";
  }
  
  ?&gt;
  
  &lt;form action="edit.php" method="post"&gt;
      &lt;div class="CSSTableGenerator" &gt;
  &lt;table&gt; 
      &lt;tr&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;ID:&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="id" value="&lt;?php echo $row[0]; ?&gt;"&gt;&lt;/td&gt;
      &lt;tr&gt;
          &lt;td&gt;First Name:&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="fName" value="&lt;?php echo $row[1]; ?&gt;"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Last Name:&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="lName" value="&lt;?php echo $row[2]; ?&gt;"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Telephone #:&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="telNum" value="&lt;?php echo $row[3]; ?&gt;"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Street Address:&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="address" value="&lt;?php echo $row[4]; ?&gt;"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;City:&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="city" value="&lt;?php echo $row[5]; ?&gt;"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;State:&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="state" value="&lt;?php echo $row[6]; ?&gt;"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Zip:&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="zip" value="&lt;?php echo $row[7]; ?&gt;"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Email:&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="email" value="&lt;?php echo $row[8]; ?&gt;"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Service:&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="service" value="&lt;?php echo $row[9]; ?&gt;"&gt;&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;Notes:&lt;/td&gt;
          &lt;td&gt;&lt;input type="text" name="notes" value="&lt;?php echo $row[10]; ?&gt;"&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;div class="CSSTableGenerator" &gt;
  &lt;table&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;input type="submit" value="Update"/&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  </code></pre>
  
  <p>Also each of these edit links is only pulling data from the primary key in the first row.  I want the edit link in the last column of each row to pull from the primary key in the first column of each row.</p>
  
  <pre><code>    &lt;?php
  include("header.php");
  include("config.php"); // connect to database
  
  mysql_query("INSERT INTO customers (id, fName, lName, telNum, address, city, state, zip, email, service, notes)
  VALUES ('$_POST[id]', '$_POST[fName]', '$_POST[lName]', '$_POST[telNum]', '$_POST[address]', '$_POST[city]', '$_POST[state]', '$_POST[zip]', '$_POST[email]', '$_POST[service]', '$_POST[notes]')")
      or die(mysql_error());
  $id = $_POST['id'];
  $fName = $_POST['fName'];
  $lName = $_POST['lName'];
  $telNum = $_POST['telNum'];
  $address = $_POST['address'];
  $city = $_POST['city'];
  $state = $_POST['state'];
  $zip = $_POST['zip'];
  $email = $_POST['email'];
  $service = $_POST['service'];
  $notes = $_POST['notes'];
  
  
  echo "&lt;h1&gt;New Client Added&lt;/h1&gt;";
  echo &lt;&lt;&lt;HTML
  &lt;html&gt;
  &lt;head&gt;
  &lt;link rel ="stylesheet" type="text/css" href="sample.css"/&gt;
  &lt;link rel ="stylesheet" type="text/css" href="TableCSSCode.css"/&gt;
  &lt;/head&gt;
  &lt;body&gt;
  &lt;div class="CSSTableGenerator"&gt;
  &lt;table&gt; 
      &lt;tr&gt;
          &lt;td&gt;ID&lt;/td&gt;
          &lt;td&gt;First Name&lt;/td&gt;
          &lt;td&gt;Last Name&lt;/td&gt;
          &lt;td&gt;Telephone #&lt;/td&gt;
          &lt;td&gt;Street Address&lt;/td&gt;
          &lt;td&gt;City&lt;/td&gt;
          &lt;td&gt;State&lt;/td&gt;
          &lt;td&gt;Zip&lt;/td&gt;
          &lt;td&gt;Email&lt;/td&gt;
          &lt;td&gt;Service&lt;/td&gt;
          &lt;td&gt;Notes&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;$id&lt;/td&gt;
          &lt;td&gt;$fName&lt;/td&gt;
          &lt;td&gt;$lName&lt;/td&gt;
          &lt;td&gt;$telNum&lt;/td&gt;
          &lt;td&gt;$address&lt;/td&gt;
          &lt;td&gt;$city&lt;/td&gt;
          &lt;td&gt;$state&lt;/td&gt;
          &lt;td&gt;$zip&lt;/td&gt;
          &lt;td&gt;$email&lt;/td&gt;
          &lt;td&gt;$service&lt;/td&gt;
          &lt;td&gt;$notes&lt;/td&gt;
      &lt;/tr&gt;
  
  &lt;/table&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  HTML;
  
  
  ?&gt;
  </code></pre>
  
  <p>Forgive me if this is a mess, I'm totally new to coding, I'm doing this for a project in an application program development class and my Prof. doesn't really seem to know what she is teaching.  Thanks in advance.</p>