title: PHP script failing on Updating Web Form
body: <p>Thanks to everyone who gave me help with previous trouble. I have my scripts working so I can add &amp; display entries. Now I was following along with this tutorial to update the entries but I am getting this error on page when I run it:
   ! ) Notice: Undefined index: id in /var/www/inventory/update.php on line 21
  Call Stack</p>
  
  <h1>Time    Memory  Function    Location</h1>
  
  <p>1   0.0000  229608  {main}( )   ../update.php:0
  The code looks like this:</p>
  
  <pre><code> &lt;?php
      ini_set("display_errors","on");
  
      $dsn='mysql:host=localhost;dbname=inventory_form';
      $username="***";
      $password="****";
      $database="inventory_form";
  
  
      try
          {
          $link=new PDO($dsn, $username,$password);
          echo 'Connected to MySQL Server';
          }
      catch (PDOException $e)
          {
          $error_message=$e-&gt;getMessage();
          echo "&lt;h1&gt;An error occurred: $error_message&lt;/h1&gt;";
          }
  
      $id=$_POST['id'];
      $query="SELECT * FROM Inventory WHERE id='$id'";
      $result=$link-&gt;query($query);
  
      while ($row = $result-&gt;fetch()) { 
          echo '&lt;b&gt;&lt;i&gt;&lt;center&gt;&lt;font size=5&gt;'. $row['FName'] .'&lt;/font&gt;&lt;/b&gt;&lt;/i&gt;&lt;/center&gt;&lt;br /n&gt;';
          echo '&lt;b&gt;&lt;i&gt;&lt;center&gt;&lt;font size=5&gt;'. $row['LName'] .'&lt;/font&gt;&lt;/b&gt;&lt;/i&gt;&lt;/center&gt;&lt;br /n&gt;';
          echo '&lt;b&gt;&lt;i&gt;&lt;center&gt;&lt;font size=5&gt;'. $row['Eqpmnt_Brwd'] .'&lt;/font&gt;&lt;/b&gt;&lt;/i&gt;&lt;/center&gt;&lt;br /n&gt;';
          echo '&lt;b&gt;&lt;i&gt;&lt;center&gt;&lt;font size=5&gt;'. $row['Service_Tag'] .'&lt;/font&gt;&lt;/b&gt;&lt;/i&gt;&lt;/center&gt;';
          echo '&lt;b&gt;&lt;i&gt;&lt;center&gt;&lt;font size=5&gt;'. $row['Date_Taken'] .'&lt;/font&gt;&lt;/b&gt;&lt;/i&gt;&lt;/center&gt;';
          echo '&lt;b&gt;&lt;i&gt;&lt;font size=5&gt;'. $row['Comments'] .'&lt;/font&gt;&lt;/b&gt;&lt;/i&gt;';
  
        }
  
      ?&gt;
  
      &lt;form action="updated.php" method="post"&gt;
      &lt;input type="hidden" name="ud_id" value="&lt;? echo "$id"; ?&gt;"&gt;
      &lt;font size=5&gt;First Name:&lt;/font&gt;&lt;input type="text" name="ud_first" maxlength="12" 
  size="12" /&gt;
      &lt;font size=5&gt;Last Name:&lt;/font&gt;&lt;input type="text" name="ud_last" maxlength="36" size="12" /&gt;
      &lt;font size=5&gt;Equipment Borrowed:&lt;/font&gt;&lt;input type="text" name="ud_Equipment_Borrowed" maxlength="60" size="14" /&gt;&lt;br /&gt;
      &lt;font size=5&gt;Service Tag:&lt;/font&gt;&lt;input type="text" name="ud_Service_Tag" maxlength="6" size="6" /&gt;&lt;br /&gt;
      &lt;font size=5&gt;Date Taken:&lt;/font&gt;&lt;input type="text" name="ud_Date_Taken" /&gt;&lt;br /&gt;
      &lt;font size=5&gt;Additional Comments:&lt;/font&gt;&lt;br /&gt; 
          &lt;textarea name="ud_Comments" maxlength="150" cols="50" rows="3"&gt;&lt;/textarea&gt; &lt;br /&gt; &lt;br /&gt;
      &lt;input type="Submit" value="Update"&gt;
      &lt;/form&gt;
      ?/
  </code></pre>
  
  <p>And then I get a bunch of errors from the updated.php script:
   Notice: Undefined variable: ud_first in /var/www/inventory/updated.php on line 19
  Call Stack</p>
  
  <h1>Time    Memory  Function    Location</h1>
  
  <p>1   0.0002  231664  {main}( )   ../updated.php:0</p>
  
  <p>( ! ) Notice: Undefined variable: ud_last in /var/www/inventory/updated.php on line 19
  Call Stack</p>
  
  <h1>Time    Memory  Function    Location</h1>
  
  <p>1   0.0002  231664  {main}( )   ../updated.php:0</p>
  
  <p>( ! ) Notice: Undefined variable: ud_Equipmnt_borrowed in /var/www/inventory/updated.php on line 19
  etc for all variables.
  That script is:</p>
  
  <pre><code>&lt;?php
  ini_set("display_errors","on");
  $dsn='mysql:host=localhost;dbname=inventory_form';
  $username="***";
  $password="****";
  $database="inventory_form";
  
  try
      {
      $link=new PDO($dsn, $username,$password);
      echo 'Record added succesfully';
      }
  catch (PDOException $e)
      {
      $error_message=$e-&gt;getMessage();
      echo "&lt;h1&gt;An error occurred: $error_message&lt;/h1&gt;";
      }
  
  $query="UPDATE contacts SET FName='$ud_first', LName='$ud_last', Eqmnt_Brwd='$ud_Equipmnt_borrowed', Service_Tag='$ud_Service_Tag', Date_Taken='$ud_Date_Taken', Comments='$ud_Comments' WHERE id='$ud_id'";
  
  echo "Record Updated";
  
  ?&gt;
  </code></pre>
  
  <p>Any help much appreciated. I'm a little confuse on how the id field is being used to make this all work. According to tutorial I should have a filled in form ready to edit for a particular entry.Thanks in advance</p>
  
  <p>Update. Here is code:</p>
  
  <pre><code>&lt;?php
  ini_set("display_errors","on");
  
  $dsn='mysql:host=localhost;dbname=inventory_form';
  $username="***";
  $password="*****";
  $database="inventory_form";
  
  
  try
      {
      $link=new PDO($dsn, $username,$password);
      echo 'Connected to MySQL Server';
      }
  catch (PDOException $e)
      {
      $error_message=$e-&gt;getMessage();
      echo "&lt;h1&gt;An error occurred: $error_message&lt;/h1&gt;";
      }
  
  $id=htmlspecialchars($_GET['id']);
  
  $query="SELECT * FROM Inventory WHERE id='$id'";
  $result=$link-&gt;query($query);
  
  while ($row = $result-&gt;fetch()) { 
      echo '&lt;b&gt;&lt;i&gt;&lt;center&gt;&lt;font size=5&gt;'. $row['FName'] .'&lt;/font&gt;&lt;/b&gt;&lt;/i&gt;&lt;/center&gt;&lt;br /n&gt;';
      echo '&lt;b&gt;&lt;i&gt;&lt;center&gt;&lt;font size=5&gt;'. $row['LName'] .'&lt;/font&gt;&lt;/b&gt;&lt;/i&gt;&lt;/center&gt;&lt;br /n&gt;';
      echo '&lt;b&gt;&lt;i&gt;&lt;center&gt;&lt;font size=5&gt;'. $row['Eqpmnt_Brwd'] .'&lt;/font&gt;&lt;/b&gt;&lt;/i&gt;&lt;/center&gt;&lt;br /n&gt;';
      echo '&lt;b&gt;&lt;i&gt;&lt;center&gt;&lt;font size=5&gt;'. $row['Service_Tag'] .'&lt;/font&gt;&lt;/b&gt;&lt;/i&gt;&lt;/center&gt;';
      echo '&lt;b&gt;&lt;i&gt;&lt;center&gt;&lt;font size=5&gt;'. $row['Date_Taken'] .'&lt;/font&gt;&lt;/b&gt;&lt;/i&gt;&lt;/center&gt;';
      echo '&lt;b&gt;&lt;i&gt;&lt;font size=5&gt;'. $row['Comments'] .'&lt;/font&gt;&lt;/b&gt;&lt;/i&gt;';
  
    }
  
  ?&gt;
  
  &lt;form action="updated.php" method="post"&gt;
  &lt;input type="hidden" name="ud_id" value="&lt;? echo "$id"; ?&gt;"&gt;
  &lt;font size=5&gt;First Name:&lt;/font&gt;&lt;input type="text" name="ud_first" maxlength="12" size="12" /&gt;
  &lt;font size=5&gt;Last Name:&lt;/font&gt;&lt;input type="text" name="ud_last" maxlength="36" size="12" /&gt;
  &lt;font size=5&gt;Equipment Borrowed:&lt;/font&gt;&lt;input type="text" name="ud_Equipment_Borrowed" maxlength="60" size="14" /&gt;&lt;br /&gt;
  &lt;font size=5&gt;Service Tag:&lt;/font&gt;&lt;input type="text" name="ud_Service_Tag" maxlength="6" size="6" /&gt;&lt;br /&gt;
  &lt;font size=5&gt;Date Taken:&lt;/font&gt;&lt;input type="text" name="ud_Date_Taken" /&gt;&lt;br /&gt;
  &lt;font size=5&gt;Additional Comments:&lt;/font&gt;&lt;br /&gt; 
      &lt;textarea name="ud_Comments" maxlength="150" cols="50" rows="3"&gt;&lt;/textarea&gt; &lt;br /&gt; &lt;br /&gt;
  &lt;input type="Submit" value="Update"&gt;
  &lt;/form&gt;
  
  
  ?&gt;
  </code></pre>