title: How to create a edit form to update records from the HTML forms using PHP and MySQL
body: <p>I have a script that updates MySQL tables with the values from an HTML and processed by PHP.
  When I click on the edit link which is on the table it redirects me to the edit page, where it shows the records fetched from the MySQL database - but it does not update the record. </p>
  
  <p>Here is my link code:</p>
  
  <pre><code>echo "&lt;td&gt;&lt;a href=\"cityproc.php?accode=$row[accode]\"&gt;&lt;img src='images/edit.png'&gt;&lt;/a&gt;&lt;/td&gt;";
  </code></pre>
  
  <p>Here is my edit page code:</p>
  
  <pre><code>&lt;?php
  session_start();
  if (!isset($_SESSION["username"])) {
      header("Location: unauthorize_access.php");
  }
  mysql_connect("localhost", "root", '')or die(mysql_error());
  mysql_select_db("webapp") or die(mysql_error());
  
  $accode = mysql_real_escape_string($_REQUEST['accode']); // is used for both $_GET/$_POST variables
  
  if(isset($_POST['submit']))
  {
  
            $city = mysql_real_escape_string($_POST['city']);
            $result = mysql_query("UPDATE `city` SET `name`='$city' WHERE accode='$accode'") or die(mysql_error());
  
            echo "&lt;b&gt;Thank you! Record UPDATED Successfully!&lt;br&gt;You'll be redirected to Home Page after (1) Seconds";
            echo "&lt;meta http-equiv=Refresh content=1;url=table.php&gt;";
  }
  elseif($accode)
  {
  
          $result = mysql_query("SELECT * FROM city WHERE accode='$accode' ");
          $myrow = mysql_fetch_assoc($result);
  
                  $code = $myrow["code"];
                  $city = $myrow["name"];
  ?&gt;
  
  
  &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
  
  &lt;head&gt;
  &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
  
  &lt;link rel="stylesheet" type="text/css" href="form2/view.css" media="all"&gt;
  &lt;script type="text/javascript" src="form2/view.js"&gt;&lt;/script&gt;
  &lt;script type="text/javascript" src="form2/calendar.js"&gt;&lt;/script&gt;
  &lt;/head&gt;
  &lt;body id="main_body" &gt;
  
      &lt;img id="top" src="form2/top.png" alt="" /&gt;
      &lt;div id="form_container"&gt;
  
          &lt;h1&gt;&lt;a&gt;City&lt;/a&gt;&lt;/h1&gt;
          &lt;form id="city" class="appnitro" enctype="multipart/form-data" method="post" action="cityproc.php"&gt;
                      &lt;div class="form_description"&gt;
          &lt;h2&gt;City&lt;/h2&gt;
                  &lt;table border="0" width="100%"&gt;
                      &lt;tr&gt;
                          &lt;td&gt;&lt;?php echo $accode; ?&gt;&lt;/td&gt;
                      &lt;/tr&gt;
              &lt;/table&gt;
  
          &lt;/div&gt;
                      &lt;table border ="0px" width="100%"&gt;
                          &lt;input type="hidden" value="&lt;? echo $myrow['accode']?&gt;" name="accode"&gt;&lt;/input&gt; 
                          &lt;tr&gt;
                              &lt;td&gt;&lt;label class="description" for="element_1"&gt;Code&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input  name="code"  type="text" maxlength="6"  Placeholder="Please enter a code" value="&lt;?php echo $code; ?&gt;" disabled="disabled" /&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td&gt;&lt;label class="description" for="element_1"&gt;Name&lt;/label&gt;&lt;/td&gt;&lt;td&gt;&lt;input  name="city" size="40" type="text" maxlength="40" Placeholder="Please enter a name" value="&lt;?php echo $city; ?&gt;"/&gt;&lt;/td&gt;
  
                          &lt;/tr&gt;
                          &lt;tr&gt;
                              &lt;td&gt;&lt;/td&gt;&lt;td colspan="2" align="center"&gt;&lt;input type="submit" name="submit" value="Save" /&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                      &lt;/table&gt;
                  &lt;/form&gt;
                  &lt;/body&gt;
      &lt;/html&gt;
  &lt;?php
  }
  ?&gt;
  </code></pre>