title: InPHP,MySQL, how do i update a row in a table using HTML form
body: <p>I have 2 PHP files for this. The first one update.php contains the user form to update the row. The next one,update_ac contains the coding to carry out this update. The problem is i do not get a proper output</p>
  
  <pre><code>&lt;?php
  $host = "localhost"; // Host name 
  $username = "root"; // Mysql username 
  $password = ""; // Mysql password 
  $db_name = "yumyum"; // Database name 
  $tbl_name = "food"; // Table name
  // Connect to server and select database.
  mysql_connect("$host", "$username", "$password") or die("cannot connect");
  mysql_select_db("$db_name") or die("cannot select DB");
  
  // get value of id that sent from address bar
  //$id=$_GET['id'];
  
  $id = $_REQUEST['id'];
  
  // Retrieve data from database 
  $sql = "SELECT * FROM $tbl_name WHERE id='$id'";
  $result = mysql_query($sql);
  $rows = mysql_fetch_array($result);
  ?&gt;
  
  &lt;table width="400" border="0" cellspacing="1" cellpadding="0"&gt;
      &lt;tr&gt;
      &lt;form name="form1" method="post" action="update_ac.php"&gt;
          &lt;td&gt;
              &lt;table width="100%" border="0" cellspacing="1" cellpadding="0"&gt;
  
                  &lt;tr&gt;
  
                      &lt;td align="center"&gt;&lt;strong&gt;name&lt;/strong&gt;&lt;/td&gt;
                      &lt;td align="center"&gt;&lt;strong&gt;price&lt;/strong&gt;&lt;/td&gt;
                      &lt;td align="center"&gt;&lt;strong&gt;Quantity&lt;/strong&gt;&lt;/td&gt;
  
                  &lt;/tr&gt;
  
                  &lt;td align="center"&gt;
                      &lt;input name="name" type="text" id="name" value="&lt;? echo $line['name']; ?&gt;"&gt;
                  &lt;/td&gt;
  
                  &lt;td align="center"&gt;
                      &lt;input name="price" type="text" id="price" value="&lt;? echo $line['price']; ?&gt;" size="15"&gt;
                  &lt;/td&gt;
  
                  &lt;td align="center"&gt;
                      &lt;input name="Quantity" type="text" id="Quantity" value="&lt;? echo $line['Quantity']; ?&gt;" size="15"&gt;
                  &lt;/td&gt;
  
  
                  &lt;td&gt;
                      &lt;input name="id" type="hidden" id="id" value="&lt;? echo $line['id']; ?&gt;"&gt;
                  &lt;/td&gt;
                  &lt;td align="center"&gt;
                      &lt;input type="submit" name="Submit" value="Submit"&gt;
                  &lt;/td&gt;
  
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/td&gt;
      &lt;/form&gt;
  &lt;/tr&gt;
  &lt;/table&gt;
  
  &lt;?php
  // close connection 
  mysql_close();
  ?&gt;
  
  **This is update_ac.php**
      &lt;?php
      $host="localhost"; // Host name 
      $username="root"; // Mysql username 
      $password=""; // Mysql password 
      $db_name="yumyum"; // Database name 
      $tbl_name="food"; // Table name 
  
      // Connect to server and select database.
      mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
      mysql_select_db("$db_name")or die("cannot select DB");
  
      // update data in mysql database 
      $sql="UPDATE $tbl_name SET name='$name', price='$price', Quantity='$Quantity' WHERE id='$id'";
      $result=mysql_query($sql);
  
      // if successfully updated. 
      if($result){
      echo "Successful";
      echo "&lt;BR&gt;";
      echo "&lt;a href='yumhome.php'&gt;View result&lt;/a&gt;";
      }
  
      else {
      echo "ERROR";
      }
  
      ?&gt;
  </code></pre>